- Posts: 10240
- Thank you received: 3644
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ // A function to disable all non-checked radios function handleDisableNonChecked(thisRadio) { var thisRow = $(thisRadio).closest('.answer-item'); // Disable non-checked radios $('#question{QID} input.radio').not(thisRadio).prop('disabled', true); // Handle "Other" text input if($('input.text', thisRow).length == 0) { $('#question{QID} input.text').prop('disabled', true); } // Add a class to the disabled rows $('#question{QID} .answer-item').not(thisRow).addClass('disabled-row'); } // Initial state (in case of returning to page if($('#question{QID} input.radio:checked').length > 0) { handleDisableNonChecked($('#question{QID} input.radio:checked')); } // Listener on the radios $('#question{QID} input.radio').on('click', function(e){ handleDisableNonChecked(this); }); // Fix the core event handler for the label div $('#question{QID} .label-clickable').unbind('click').on('click', function(e){ if(!$(this).parent().find('input.radio').is(':disabled')) { $(this).parent().find('input.radio').trigger('click'); } }); }); </script>
.disabled-row .label-clickable{ opacity: 0.45; cursor: not-allowed; }
So your latter solution is preferred and works great!3) Handles initial states in case of returning to the group