- Posts: 45
- Thank you received: 1
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ var thisQuestion = $('#question{QID}'); // Insert selects $('.answer-item.answer_cell_change', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\ <option value="" selected>Bitte auswählen</option>\ <option value="1">Zunahme um</option>\ <option value="0">Gleichbleibend</option>\ <option value="2">Abnahme um</option>\ </select>'); // Listeners $('.inserted-select', thisQuestion).on('change', function(i) { if($(this).val() != '') { $(this).closest('.answer-item').find('input:text').val($('option:selected', this).val()).trigger('change'); } else { $(this).closest('.answer-item').find('input:text').val('').trigger('change'); } }); // Returning to page $('.with-select input:text', thisQuestion).each(function(i) { var thisCell = $(this).closest('.answer-item'); var inputText = $.trim($(this).val()); $('select.inserted-select', thisCell).val(inputText); }); // Listener on column 2 inputs $('.answer-item.answer_cell_change input:text', thisQuestion).on('keyup change', function(e) { var thisValue = $.trim($(this).val()); // Numerics only if($.isNumeric(thisValue) === false) { // Strip out non-numerics characters newValue = thisValue.replace(/\D/g,''); $(this).val(newValue).trigger('change'); } // Max/min values var maxAllowed = 100; var minAllowed = 0; if (thisValue > maxAllowed) { alert('The maximum allowed is '+maxAllowed+'.'); $(this).val(maxAllowed); } else if (thisValue < minAllowed) { alert('The minimum allowed is '+minAllowed+'.'); $(this).val(minAllowed); } }); // Clean-up styles $('select.inserted-select', thisQuestion).css({ 'max-width': '100%' }); $('.with-select input:text', thisQuestion).css({ 'position': 'absolute', 'left': '-9999em' }); }); </script> And this is how it looks like when it is duplicated: [attachment=31896]lime.jpg[/attachment] Can somebody help me to prevent the field from duplicating (or triplicating when you send it again without mandatory data)? Thanks in advance, Ralf
// Listener on column 2 inputs $('.answer-item.answer_cell_change input:text', thisQuestion).on('keyup change', function(e) { var thisValue = $.trim($(this).val()); // Numerics only if($.isNumeric(thisValue) === false) { // Strip out non-numerics characters newValue = thisValue.replace(/\D/g,''); $(this).val(newValue).trigger('change'); } // Max/min values var maxAllowed = 100; var minAllowed = 0; if (thisValue > maxAllowed) { alert('The maximum allowed is '+maxAllowed+'.'); $(this).val(maxAllowed); } else if (thisValue < minAllowed) { alert('The minimum allowed is '+minAllowed+'.'); $(this).val(minAllowed); } });
Please Log in to join the conversation.
Please Log in to join the conversation.
// Listener on column 2 inputs $('.answer-item.answer_cell_change input:text', thisQuestion).on('keyup change', function(e) { var thisValue = $.trim($(this).val());
// Listener on column 2 inputs $('.answer-item.answer_cell_Wert input:text', thisQuestion).on('keyup change', function(e) { var thisValue = $.trim($(this).val());
Please Log in to join the conversation.
Please Log in to join the conversation.
<script type="text/javascript" data-author="Tony Partner"> $(document).on('ready pjax:scriptcomplete',function(){ var thisQuestion = $('#question{QID}'); if($('.inserted-select', thisQuestion).length == 0) { // Insert selects $('.answer-item.answer_cell_change', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\ <option value="" selected>Bitte auswählen</option>\ <option value="1">Zunahme um</option>\ <option value="0">Gleichbleibend</option>\ <option value="2">Abnahme um</option>\ </select>'); // Listeners $('.inserted-select', thisQuestion).on('change', function(i) { if($(this).val() != '') { $(this).closest('.answer-item').find('input:text').val($('option:selected', this).val()).trigger('change'); } else { $(this).closest('.answer-item').find('input:text').val('').trigger('change'); } }); // Returning to page $('.with-select input:text', thisQuestion).each(function(i) { var thisCell = $(this).closest('.answer-item'); var inputText = $.trim($(this).val()); $('select.inserted-select', thisCell).val(inputText); }); // Listener on column 2 inputs $('.answer-item.answer_cell_change input:text', thisQuestion).on('keyup change', function(e) { var thisValue = $.trim($(this).val()); // Numerics only if($.isNumeric(thisValue) === false) { // Strip out non-numerics characters newValue = thisValue.replace(/\D/g,''); $(this).val(newValue).trigger('change'); } // Max/min values var maxAllowed = 100; var minAllowed = 0; if (thisValue > maxAllowed) { alert('The maximum allowed is '+maxAllowed+'.'); $(this).val(maxAllowed); } else if (thisValue < minAllowed) { alert('The minimum allowed is '+minAllowed+'.'); $(this).val(minAllowed); } }); // Clean-up styles $('select.inserted-select', thisQuestion).css({ 'max-width': '100%' }); $('.with-select input:text', thisQuestion).css({ 'position': 'absolute', 'left': '-9999em' }); } }); </script>
Please Log in to join the conversation.
<script type="text/javascript" data-author="Tony Partner"> $(document).on('ready pjax:scriptcomplete',function(){ var thisQuestion = $('#question{QID}'); if($('.inserted-select', thisQuestion).length == 0) { // Column-specific classes $('tr.subquestion-list', thisQuestion).each(function(i) { $('th, td', this).each(function(i) { $(this).addClass('column-'+i); }); }); // Insert selects into column 1 if($('.answer-item.column-1 .inserted-select', thisQuestion).length == 0) { $('.answer-item.column-1', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\ <option value="" selected>Bitte auswählen...</option>\ <option value="1">Zunahme um</option>\ <option value="0">Gleichbleibend</option>\ <option value="2">Abnahme um</option>\ </select>'); } // Insert selects into column 3 if($('.answer-item.column-3 .inserted-select', thisQuestion).length == 0) { $('.answer-item.column-3', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\ <option value="" selected>Bitte auswählen...</option>\ <option value="1">Zunahme um</option>\ <option value="0">Gleichbleibend</option>\ <option value="2">Abnahme um</option>\ </select>'); } // Insert selects into column 5 if($('.answer-item.column-5 .inserted-select', thisQuestion).length == 0) { $('.answer-item.column-5', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\ <option value="" selected>Bitte auswählen...</option>\ <option value="1">Zunahme um</option>\ <option value="0">Gleichbleibend</option>\ <option value="2">Abnahme um</option>\ </select>'); } // Listeners $('.inserted-select', thisQuestion).on('change', function(i) { if($(this).val() != '') { $(this).closest('.answer-item').find('input:text').val($('option:selected', this).val()).trigger('change'); } else { $(this).closest('.answer-item').find('input:text').val('').trigger('change'); } }); // Returning to page $('.with-select input:text', thisQuestion).each(function(i) { var thisCell = $(this).closest('.answer-item'); var inputText = $.trim($(this).val()); $('select.inserted-select', thisCell).val(inputText); }); // Listener on column 2 inputs $('.answer-item.answer_cell_change input:text', thisQuestion).on('keyup change', function(e) { var thisValue = $.trim($(this).val()); // Numerics only if($.isNumeric(thisValue) === false) { // Strip out non-numerics characters newValue = thisValue.replace(/\D/g,''); $(this).val(newValue).trigger('change'); } // Max/min values var maxAllowed = 100; var minAllowed = 0; if (thisValue > maxAllowed) { alert('The maximum allowed is '+maxAllowed+'.'); $(this).val(maxAllowed); } else if (thisValue < minAllowed) { alert('The minimum allowed is '+minAllowed+'.'); $(this).val(minAllowed); } }); // Clean-up styles $('select.inserted-select', thisQuestion).css({ 'max-width': '100%' }); $('.with-select input:text', thisQuestion).css({ 'position': 'absolute', 'left': '-9999em' }); } }); </script>
Please Log in to join the conversation.
<script type="text/javascript" data-author="Tony Partner"> $(document).on('ready pjax:scriptcomplete',function(){ var thisQuestion = $('#question{QID}'); if($('.inserted-select', thisQuestion).length == 0) { // Column-specific classes $('tr.subquestion-list', thisQuestion).each(function(i) { $('th, td', this).each(function(i) { $(this).addClass('column-'+i); }); }); // Insert selects into column 1 $('.answer-item.column-1', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\ <option value="" selected>Bitte auswählen...</option>\ <option value="1">Zunahme um</option>\ <option value="0">Gleichbleibend</option>\ <option value="2">Abnahme um</option>\ </select>'); // Insert selects into column 3 $('.answer-item.column-3', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\ <option value="" selected>Bitte auswählen...</option>\ <option value="1">Zunahme um</option>\ <option value="0">Gleichbleibend</option>\ <option value="2">Abnahme um</option>\ </select>'); // Insert selects into column 5 $('.answer-item.column-5', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\ <option value="" selected>Bitte auswählen...</option>\ <option value="1">Zunahme um</option>\ <option value="0">Gleichbleibend</option>\ <option value="2">Abnahme um</option>\ </select>'); // Listeners $('.inserted-select', thisQuestion).on('change', function(i) { if($(this).val() != '') { $(this).closest('.answer-item').find('input:text').val($('option:selected', this).val()).trigger('change'); } else { $(this).closest('.answer-item').find('input:text').val('').trigger('change'); } }); // Returning to page $('.with-select input:text', thisQuestion).each(function(i) { var thisCell = $(this).closest('.answer-item'); var inputText = $.trim($(this).val()); $('select.inserted-select', thisCell).val(inputText); }); // Listener on column 2 inputs $('.answer-item.answer_cell_change input:text', thisQuestion).on('keyup change', function(e) { var thisValue = $.trim($(this).val()); // Numerics only if($.isNumeric(thisValue) === false) { // Strip out non-numerics characters newValue = thisValue.replace(/\D/g,''); $(this).val(newValue).trigger('change'); } // Max/min values var maxAllowed = 100; var minAllowed = 0; if (thisValue > maxAllowed) { alert('The maximum allowed is '+maxAllowed+'.'); $(this).val(maxAllowed); } else if (thisValue < minAllowed) { alert('The minimum allowed is '+minAllowed+'.'); $(this).val(minAllowed); } }); // Clean-up styles $('select.inserted-select', thisQuestion).css({ 'max-width': '100%' }); $('.with-select input:text', thisQuestion).css({ 'position': 'absolute', 'left': '-9999em' }); } }); </script>
Please Log in to join the conversation.
Please Log in to join the conversation.
<script type="text/javascript" data-author="Tony Partner"> $(document).on('ready pjax:scriptcomplete',function(){ // Identify the questions var qArrayID = {QID}; var qArray = $('#question'+qArrayID); var qMultiText = qArray.nextAll('.multiple-short-txt:eq(0)'); var qMultiTextBis = qMultiText.nextAll('.multiple-short-txt:eq(0)'); // Hide the multi-short-text question $(qMultiText).hide(); $(qMultiTextBis).hide(); // Remove the core column widths $('table.questions-list col:not(.col-answers)', qArray).css('width', 'auto'); // Insert the header cells $('table.questions-list thead td:eq(0)', qArray).after('<th class="answer-text inserted-column-label" /></th><th class="answer-text-bis inserted-column-label-bis" /></th>'); $('.inserted-column-label, .inserted-column-label-bis', qArray).css('width','10%'); // Insert the answer row cells $('tr.answers-list', qArray).each(function(i) { $('.answertext', this).after('<td class="answer-item text-item"></td><td class="answer-item text-item-bis"></td>'); }); // Load the column label for the text inputs $('.inserted-column-label:eq(0)', qArray).text($('.ls-label-question', qMultiText).text()); $('.inserted-column-label-bis:eq(0)', qArray).text($('.ls-label-question', qMultiTextBis).text()); // Loop through the multi-short-text sub-questions $('li.answer-item', qMultiText).each(function(i) { // Move the text inputs into the array $('input[type="text"]', this).appendTo($('tr.answers-list:eq('+i+') .text-item', qArray)); }); $('li.answer-item', qMultiTextBis).each(function(i) { // Move the text inputs into the array $('input[type="text"]', this).appendTo($('tr.answers-list:eq('+i+') .text-item-bis', qArray)); }); }); </script>
<script type="text/javascript" data-author="Tony Partner"> $(document).on('ready pjax:scriptcomplete',function(){ // Identify the questions var qArrayID = {QID}; var qArray = $('#question'+qArrayID); var qMultiText = qArray.nextAll('.multiple-short-txt:eq(0)'); var qMultiTextBis = qMultiText.nextAll('.multiple-short-txt:eq(0)'); if($('.inserted-column-label', qArray).length == 0) { // Hide the multi-short-text question $(qMultiText).hide(); $(qMultiTextBis).hide(); // Remove the core column widths $('table.questions-list col:not(.col-answers)', qArray).css('width', 'auto'); // Insert the header cells $('table.questions-list thead td:eq(0)', qArray).after('<th class="answer-text inserted-column-label" /></th><th class="answer-text-bis inserted-column-label-bis" /></th>'); $('.inserted-column-label, .inserted-column-label-bis', qArray).css('width','10%'); // Insert the answer row cells $('tr.answers-list', qArray).each(function(i) { $('.answertext', this).after('<td class="answer-item text-item"></td><td class="answer-item text-item-bis"></td>'); }); // Load the column label for the text inputs $('.inserted-column-label:eq(0)', qArray).text($('.ls-label-question', qMultiText).text()); $('.inserted-column-label-bis:eq(0)', qArray).text($('.ls-label-question', qMultiTextBis).text()); // Loop through the multi-short-text sub-questions $('li.answer-item', qMultiText).each(function(i) { // Move the text inputs into the array $('input[type="text"]', this).appendTo($('tr.answers-list:eq('+i+') .text-item', qArray)); }); $('li.answer-item', qMultiTextBis).each(function(i) { // Move the text inputs into the array $('input[type="text"]', this).appendTo($('tr.answers-list:eq('+i+') .text-item-bis', qArray)); }); } }); </script>
Please Log in to join the conversation.