Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC: modifying "array dual scale" questions

modifying "array dual scale" questions 1 year 3 weeks ago #94021

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 3813
  • Thank you received: 683
  • Karma: 327
Okay, in 1.92, set the question to non-mandatory and use this script. In addition to the above behaviour, it will:

1) Uncheck and hide the "No Answer" options
2) Pop up an alert and abort the submit function if a row is unanswered.
<script type="text/javascript" charset="utf-8">
	$(document).ready(function() {
 
		moveRowLabels({self.qid});
 
		function moveRowLabels(qID) {
 
			var alertMsg = 'One or more mandatory questions have not been answered. You cannot proceed until these have been completed.';
 
			// Add some classes
			$('#question'+qID).addClass('moveRowLabelsQ');
			$('#question'+qID+' table.question tbody td').not('.dual_scale_separator').addClass('answer-item radio-item');
 
			// Hide the first column
			$('#question'+qID+' th.header_answer_text, #question'+qID+' th.answertext').hide();
 
			// Uncheck and hide the "No Answer" columns
			$('#question'+qID+' .header_no_answer').hide().prev().hide('header_separator');
			$('#question'+qID+' input.radio[value=""]').attr('checked', false).closest('td').hide().prev().hide('header_separator');
 
			// Insert the subquestion text into the scale separators
			$('#question'+qID+' table.question tbody').each(function(i){
				$('.dual_scale_separator:eq(0)', this).text($('.answertext', this).text());
			});
 
			// Reset the column widths
			$('#question'+qID+' col').css({ 'width':'auto' });
 
			// Only one radio clicked allowed per row
			$('#question'+qID+' table.question input.radio').click(function() {
				var parentRow = $(this).closest('tr');
				$('.active', parentRow).removeClass('active');
				$(this).addClass('active');
				$('input.radio', parentRow).not('.active').attr('checked', false);
			});			
			$('#question'+qID+' table.question td.radio-item').click(function(event) {
				var parentRow = $(this).closest('tr');
				$('.active', parentRow).removeClass('active');
				$('input.radio', this).addClass('active');
				$('input.radio', parentRow).not('.active').attr('checked', false);
			});
 
			// At least one radio clicked per row
			// Interrupt the submit function
			$('#movenextbtn, #movesubmitbtn').click(function(){
				var error = 0;
				$('#question'+qID+' table.question tbody.error').removeClass('error');
				$('#question'+qID+' table.question tbody').each(function(i){
					if($('input.radio:checked', this).length == 0) {
						error = 1;
						$(this).addClass('error');
					}
				});
				if(error == 1) {
					alert(alertMsg);
					return false;
				}
			});
		}
    });
</script>

And then use something like this at the end of template.css:
.moveRowLabelsQ table.question tbody td.answer-item { /* radio cells */
	width: 30px;
}
 
.moveRowLabelsQ table.question  td.dual_scale_separator { /* question cell */
	width: 80px;
}
 
.moveRowLabelsQ table.question tbody.error td.answer-item { /* Error cells */
background: pink;
}
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.114 seconds
Donation Image