- Posts: 4
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
Please Log in to join the conversation.
Please Log in to join the conversation.
Thank you for the very quick reply !
But you did not show us which script you used to insert the text boxes.
Please Log in to join the conversation.
Please Log in to join the conversation.
Please Log in to join the conversation.
Please Log in to join the conversation.
Please Log in to join the conversation.
<script type="text/javascript" data-author="Tony Partner"> $(document).ready(function() { // A function to add or remove rows of an Array (Multi Flexible)(Text) question function varLengthArray(qID) { if ($('#question'+qID+'').length > 0) { var thisQuestion = $('#question'+qID); // The HTML content of the Add/Remove elements - modify as you wish var addContent = '[+] Add row'; var removeContent = '[-] Remove row'; // The classes for the Add/Remove elements - modify as you wish // See https://getbootstrap.com/docs/5.0/getting-started/introduction/ var addClasses = 'inserted-button add btn btn-success'; var removeClasses = 'inserted-button remove btn btn-danger'; // The styles for the Add/Remove elements - modify as you wish // These could be placed in your custom.css file. var addStyles = 'margin:10px 0 10px 10px; padding:1px 5px; text-align:center; width:auto; cursor:pointer; float:left;'; var removeStyles = 'margin:10px 0 10px 10px; padding:1px 5px; text-align:center; width:auto; cursor:pointer; float:left;'; // Insert the buttons $( 'table.ls-answers', thisQuestion).after('<div class="button-wrapper">\ <button type="button" class="'+addClasses+'" style="'+addStyles+'">'+addContent+'</button>\ <button type="button" class="'+removeClasses+'" style="display: none; '+removeStyles+'">'+removeContent+'</button>\ </div>'); // Listeners on the buttons $('.inserted-button.add', thisQuestion).on('click', function (event) { addRow(); }); $('.inserted-button.remove', thisQuestion).on('click', function (event) { removeRow(); }); // Define the relevant rows var relevantRows = $('tr.subquestion-list:not(.ls-irrelevant)', thisQuestion); // Function to add a row, show the "Remove" element and hide the "Add" element if all rows are shown function addRow() { $('[data-visible="false"]:first', thisQuestion).attr('data-visible', 'true').show(); $('.inserted-button.remove', thisQuestion).show(); console.log($('[data-visible="true"]', thisQuestion).length+' == '+$(relevantRows).length - 1); if ($('[data-visible="false"]', thisQuestion).length == 0) { $('.inserted-button.add', thisQuestion).hide(); } $('.inserted-button.add', thisQuestion).blur(); } // Function to remove a row, clear the contents of the removed row, // show the "Add" element if the last row is hidden and hide the "Remove" element if only the first row is shown function removeRow() { $('[data-visible="true"]:last input:text', thisQuestion).val('').trigger('keyup'); $('[data-visible="true"]:last .inserted-select', thisQuestion).val('').trigger('change'); $('[data-visible="true"]:last', thisQuestion).attr('data-visible', 'false').hide(); $('.inserted-button.add', thisQuestion).show(); if ($('[data-visible="true"]', thisQuestion).length == 0) { $('.inserted-button.remove', thisQuestion).hide(); } $('.inserted-button.remove', thisQuestion).blur(); } // Initially hide all except first row or any rows with populated inputs $(relevantRows).slice(1).each(function(i) { $( this ).attr('data-visible', 'false').hide(); $('input[type=text]', this).each(function(i) { if ($.trim($(this).val()) != '') { $(this).closest('tr').attr('data-visible', 'true').show(); $('.inserted-button.remove', thisQuestion).show(); } }); }); } } // Call the function with a question ID varLengthArray({QID}); }); </script>
Please Log in to join the conversation.
Please Log in to join the conversation.