- Posts: 40
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Identify the questions var q1 = $('#question'+{QID}+''); var q2 = $(q1).nextAll('.text-short:eq(0)'); // Hide the short-text question $(q2).hide(); // Move the hidden text input into the array $('th.answertext:last', q1).append($('input[type="text"]', q2)); // Some styling... $('input[type="text"]', q1).css({ 'width': '50%' }); }); </script>
<script> $(document).ready(function(){ $('button#movesubmitbtn').on('click',function(){ var $otherRow = $('div.array-flexible-row table.subquestions-list tr:has("input:text")'); for(var i=0;i<$otherRow.length;i++){ var checkedRadio = $otherRow.eq(i).find('td:not("td.noanswer-item")').find('input:checked').length; var boxVal = $.trim($otherRow.eq(i).find('input:text').val()); if(((checkedRadio != 0) && (boxVal == "")) || ((checkedRadio == 0) && (boxVal != ""))){ alert('Please review your answer in other specify row.'); return false; } break; } }); //clear other specify value on click of no answer $('td.noanswer-item').on('click',function(){ $(this).parent().find('input:text').val(''); }); //uncheck no answer on keydown inside otherspecify box. $('div.array-flexible-row table.subquestions-list input:text').on('keydown',function(){ $(this).parent().parent().find('td.noanswer-item input:radio').prop('checked',false); }); }); </script>
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Identify the questions var thisQuestion = $('#question'+{QID}+''); var nextQuestion = $(thisQuestion).nextAll('.text-short:eq(0)'); // Hide the short-text question $(nextQuestion).hide(); // Move the hidden text input into the array $('th.answertext:last', thisQuestion).append($('input[type="text"]', nextQuestion)).closest('tr').addClass('otherRow'); // Some styling... $('input[type="text"]', thisQuestion).css({ 'width': '50%' }); // Handle the "Other" radios $('input[type="text"]', thisQuestion).on('keyup change',function(event){ event.stopPropagation(); if($.trim($(this).val()) == '') { $('.otherRow input:radio[value!=""]', thisQuestion).prop('checked',false); $('.otherRow input:radio[value=""]', thisQuestion).click(); } else { $('.otherRow input:radio[value=""]', thisQuestion).prop('checked',false); } }); // Handle the "Other" text input $('.otherRow input.radio', thisQuestion).on('click',function(event){ if($(this).attr('value') == '') { $('.otherRow input[type="text"]', thisQuestion).val(''); } }); // Validate the "Other" text input(s) on submit if($('#movenextbtn, #movesubmitbtn').attr('data-inserted-other') != 'true') { // We're only doing this once on this page $('#movenextbtn, #movesubmitbtn').attr('data-inserted-other', 'true').on('click.insertedOther', function (event) { var otherError = 0; $('.array-flexible-row .otherRow').each(function(i) { if(($('input:radio[value!=""]:checked', this).length > 0 && $('input[type="text"]', this).val() == '') || ($('input:radio[value!=""]:checked', this).length == 0 && $('input[type="text"]', this).val() != '')) { otherError = 1; } }); if(otherError == 1) { alert('Please review your answer in the "Other" row(s).'); return false; } }); } }); </script>