- Posts: 51
- Thank you received: 4
Ask the community, share ideas, and connect with other LimeSurvey users!
$.fn.specialArraySF = function(options){ var settings = $.extend({ },options); return this.each(function() { $('#ls-button-submit').on('click', function(e) { var failTest = ""; $(' tr[id^="javatbd"]').each(function(i) { if ($('td > input[type="text"]', this).val() === "") { $(this).addClass('has-error'); failTest = 1; $('th, td', this).css({'background':'#F39A8B'}); document.querySelector('#softmandatory-alert').style.visibility = "visible"; } else { $(this).removeClass('has-error'); $('th, td', this).css({'background':'initial'}); } }); if(failTest==1){ setTimeout(assignNonresponse(), 100); e.preventDefault(); e.stopPropagation(); } else { $('.exclusive-item input[type="text"]', thisRow).trigger('keyup'); } }); function assignNonresponse(){ $(' tr[id^="javatbd"].has-error').each(function (i) { $(this).removeClass("has-error"); $(".answer_cell_m97", this).each(function(i){ $("input[id$='_cbox']", this)[0].checked = true; }); console.log($(".answer_cell_m97", this)[0].value); // too early for expressionmanager $('.exclusive-item input[type="text"]', thisRow).trigger('keyup'); }); } }); };
Please Log in to join the conversation.
Please Log in to join the conversation.
$.fn.mixedArrayPlugin = function (options) { var settings = $.extend({ qid : '' },options); return this.each(function(){var qID = settings.qid; var thisQuestion = $('#question' + qID); //this is just for style var table = document.querySelector('.mixedArray > .answer-container > table'); table.classList.remove("table-bordered"); table.classList.add("table"); // find input label and hide it var ths = $("th"); for (var t of ths) { if (t.textContent.includes("input")) { t.style.visibility="hidden"; } } //setting up the different input styles var rows = $('tr.questions-list'); for (var r of rows) { for (i = 0; i < r.children.length; i++) { if (i == 1) { r.children[i].classList.add('stayText'); } else { r.children[i].classList.add('radioB'); r.children[i].classList.add('exclusive-item'); } } } var change = $('td.radioB > input[type = "text"]'); change.each(function () { var thisID = this.id; $(this).hide(); var radioButton = document.createElement('input'); radioButton.type = 'radio'; radioButton.class = 'missingButton'; radioButton.class = 'radio-item'; radioButton.id = thisID + '_cbox'; this.parentNode.appendChild(radioButton); }); // removes input on selection of radio, only one radio selectable at once $('.exclusive-item input[type="radio"]').on('change', function (e) { var thisRow = $(this).closest('tr.subquestion-list'); var thisCell = $(this).closest('td.answer-item'); var allB = $('td.radioB', thisRow); if ($(this).is(':checked')) { $('input[type="text"]', thisCell).val('1'); $('.stayText input[type="text"]', thisRow).val(''); for (var a of allB) { if (this.parentNode == a) { } else { //console.log('here', a.children[1]); a.children[1].value = ''; a.children[3].checked = false; } } } // Fire Expression Manager $('.exclusive-item input[type="text"]', thisRow).trigger('keyup'); }); //remove checked radio on text input $('.stayText input[type="text"]').on('keyup change', function (e) { var thisRow = $(this).closest('tr.subquestion-list'); var thisCell = $(this).closest('td.answer-item'); var allB2 = $('td.radioB', thisRow); if ($.trim($(this).val()) !== '') { for (var a of allB2) { a.children[1].value = ''; a.children[3].checked = false; } } // Fire Expression Manager $('.exclusive-item input[type="text"]', thisRow).trigger('keyup'); }); }); };[/i][/i][/i]
Please Log in to join the conversation.
Please Log in to join the conversation.
Please Log in to join the conversation.
function softMandatory() { $('#ls-button-submit').on('click', function (e) { var failTest = ""; $(' tr[id^="javatbd"]').each(function (i) { if ($('td > input[type="text"]', this).val() === "") { $(this).addClass('has-error'); failTest = 1; $('th, td', this).css({ 'background': '#F39A8B' }); } else { $(this).removeClass('has-error'); $('th, td', this).css({ 'background': 'initial' }); } }); if (failTest == 1 && !$('#softmandatory-alert').hasClass('shown')) { console.log("stopping the default"); setTimeout(assignNonresponse(), 100); e.preventDefault(); e.stopPropagation(); $('#softmandatory-alert').css('visibility', 'visible').addClass('shown'); } }); function assignNonresponse() { $(' tr[id^="javatbd"].has-error').each(function (i) { $(this).removeClass("has-error"); $(".answer_cell_m97", this).each(function (i) { $("input[id$='_cbox']", this)[0].checked = true; }); console.log($(".answer_cell_m97", this)[0].value); }); } }
Please Log in to join the conversation.
Please Log in to join the conversation.