- Posts: 10634
- Thank you received: 3698
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Last Option In Array (Numbers) (Checkboxes) column Excludes All Others
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
3 years 3 months ago - 3 years 3 months ago #208865
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Last Option In Array (Numbers) (Checkboxes) column Excludes All Others
Apply the exclusive script before the fixed-row script.
Code:
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ // Identify this question var qID = '{QID}'; var thisQuestion = $('#question'+qID); // Assign column-specific attributes and classnames $('tr.subquestion-list', thisQuestion).each(function(i) { $('> *', this).each(function(i) { $(this).attr('data-column', i); }); }); $('tr.subquestion-list:last td.answer-item', thisQuestion).addClass('exclusive-item'); // A function to un-check boxes function resetCheckbox(thisItem) { $(':hidden', thisItem).val(''); $(':checkbox', thisItem).prop('checked', false).trigger('change'); } // Listener on the checkboxes $(':checkbox', thisQuestion).on('change', function(e) { if($(this).is(':checked')) { var thisItem = $(this).closest('.answer-item'); var thisColumn = $(thisItem).attr('data-column'); var items = $('td.answer-item[data-column="'+thisColumn+'"].exclusive-item', thisQuestion); if($(thisItem).hasClass('exclusive-item')) { items = $('td.answer-item[data-column="'+thisColumn+'"]:not(.exclusive-item)', thisQuestion); } $.each(items, function(i, el) { resetCheckbox(el); }); } }); // The subquestion code to place in the last position var fixedCode = 'A20'; // Move the "fixed" row to the end $('table.subquestion-list tbody:last', thisQuestion).append($('tr[id$="X'+qID+fixedCode+'"]')); // Fix up the array row background colours $('tr.answers-list', thisQuestion).each(function(i){ $(this).removeClass('array1 array2').addClass('array'+(2-(i%2))); }); }); </script>
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 3 years 3 months ago by tpartner.
The topic has been locked.
- surveySn
- Topic Author
- Offline
- Premium Member
Less
More
- Posts: 136
- Thank you received: 4
3 years 3 months ago #208868
by surveySn
Replied by surveySn on topic Last Option In Array (Numbers) (Checkboxes) column Excludes All Others
Hi Tony
If random order is used
Can't fixed the last row,
If random order is used
Can't fixed the last row,
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10634
- Thank you received: 3698
3 years 3 months ago #208891
by tpartner
Sample survey attached:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Last Option In Array (Numbers) (Checkboxes) column Excludes All Others
Code:
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ // Identify this question var qID = '{QID}'; var thisQuestion = $('#question'+qID); // Assign column-specific attributes and classnames $('tr.subquestion-list', thisQuestion).each(function(i) { $('> *', this).each(function(i) { $(this).attr('data-column', i); }); }); $('tr.subquestion-list:last td.answer-item', thisQuestion).addClass('exclusive-item'); // A function to un-check boxes function resetCheckbox(thisItem) { $(':hidden', thisItem).val(''); $(':checkbox', thisItem).prop('checked', false).trigger('change'); } // Listener on the checkboxes $(':checkbox', thisQuestion).on('change', function(e) { if($(this).is(':checked')) { var thisItem = $(this).closest('.answer-item'); var thisColumn = $(thisItem).attr('data-column'); var items = $('td.answer-item[data-column="'+thisColumn+'"].exclusive-item', thisQuestion); if($(thisItem).hasClass('exclusive-item')) { items = $('td.answer-item[data-column="'+thisColumn+'"]:not(.exclusive-item)', thisQuestion); } $.each(items, function(i, el) { resetCheckbox(el); }); } }); // The subquestion code to place in the last position var fixedCode = 'A20'; // Move the "fixed" row to the end $('table.subquestion-list tbody:last', thisQuestion).append($('tr[id$="X'+qID+fixedCode+'"]')); // Fix up the array row background colours $('tr.answers-list', thisQuestion).each(function(i){ $(this).removeClass('array1 array2').addClass('array'+(2-(i%2))); }); }); </script>
Sample survey attached:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- surveySn
- Topic Author
- Offline
- Premium Member
Less
More
- Posts: 136
- Thank you received: 4
3 years 3 months ago #208929
by surveySn
Replied by surveySn on topic Last Option In Array (Numbers) (Checkboxes) column Excludes All Others
Think you Tony
The topic has been locked.