Alternate ranking question - Dynamic answer options

More
4 weeks 20 hours ago #159920 by tpartner
tpartner replied the topic: Alternate ranking question - Dynamic answer options
Oh, I see your problem now - the filtering is working but the piping is not. Something in the style declaration is messing with Expression Manager.

Use this script. Note that in the style rules you must leave a space after the opening curly braces and before the closing braces.

<script type="text/javascript" charset="utf-8"> 
	$(document).on('ready pjax:complete',function() {
 
		// Identify this question
		var thisQuestion = $('#question{QID}');
 
		// Define some "Choose" text
		var choosetext = 'Please choose...';
 
		// Number of visible rows
		var rowCount = $('tr.answer-item:visible', thisQuestion).length;
 
		// Loop through all drop-downs
		$('tr.answer-item select', thisQuestion).each(function(i) {
 
			// Reset if value is above the number of visible rows
			if($(this).val() > rowCount) {
				$(this).prepend('<option value="">'+choosetext+'</option>').val('');
				checkconditions(this.value, this.name, this.type);
			}
 
			// Remove all unnecessary options
			$('option', this).filter(function() {
				return this.value > rowCount;
			}).remove(); 
		});
 
		// Listener on the dropdowns
		$('tr.answer-item select', thisQuestion).on('change', function(e) {
			// Handle non-unique answers
			 handleDuplicates();
		});
 
		function handleDuplicates() {
			$('.question-item', thisQuestion).removeClass('duplicate-row');
			$('tr.answer-item select', thisQuestion).each(function(i) {
				if(!$(this).closest('.question-item').hasClass('duplicate-row') && $(this).val() != '') {
					var thisSelect = $(this);
					var selectedValue = $(this).val();
					$('tr.answer-item select', thisQuestion).not(this).each(function(i) {
						if($(this).val() == selectedValue) {
							$(this).closest('.question-item').addClass('duplicate-row');
							$(thisSelect).closest('.question-item').addClass('duplicate-row');
						}
					});
				}
			});
		}
		handleDuplicates();
 
		//Insert new style rules
		var newStyle = '<style type="text/css">\
							.duplicate-row { background-color: #E74C3C; }\
							.duplicate-row .answertext { color: #FFFFFF; }\
						</style>';		
		$("head link[rel='stylesheet']").last().after(newStyle);
	});
</script>

Working survey attached:

File Attachment:

File Name: limesurvey...0-21.lss
File Size:47 KB

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:

Please Log in to join the conversation.

More
3 weeks 5 days ago #159946 by Gensz78
Gensz78 replied the topic: Alternate ranking question - Dynamic answer options
Thank you so much! It's working beautifully now!

Gen

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!