- Posts: 3
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
// A jQuery plugin ensure that there are no rows with single answers (function( $ ){ $.fn.lsHandleArray = function(options) { var opts = $.extend( { alertText: 'Please complete the indicated rows.' }, options); return this.each(function() { var thisQuestion = $(this); // Interrupt the Next/Submit click $('#movenextbtn, #movesubmitbtn').bind('click', function () { // Reset $('tr.answers-list', thisQuestion).removeClass('invalid-answer'); // Loop through the array rows $('tr.answers-list', thisQuestion).each(function(i) { if($('input.radio:checked', this).length == 1) { $(this).addClass('invalid-answer'); } }); // Pop up alert and abort submit if invalid rows found if($('tr.invalid-answer', thisQuestion).length > 0) { alert(opts.alertText); $('#movenextbtn, #movesubmitbtn').blur(); return false; } }); }); }; })( jQuery );
tr.invalid-answer { background: pink; }
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { $('#question{QID}').lsHandleArray({alertText: 'Please complete the indicated rows.'}); }); </script>