Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Fields are duplicating when page is reloaded for mandatory questions

  • ralfkunze
  • ralfkunze's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 year 4 months ago #239156 by ralfkunze
Thanks a lot to tpartner - but also to Joffm!
Ralf

Please Log in to join the conversation.

  • ralfkunze
  • ralfkunze's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 year 4 months ago #239183 by ralfkunze
Sorry tpartner, 
I have another question: I am using still another javascript from you which allows to show to questions (text and radio button) beside each other. Unfortunately this script also doubles the first column (the text box column) when the page is re-loaded e.g. by mandatory values. But only the column, not the text boxes (see screenshot). 

Here is the script I am using: 
Code:
<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>

Could you please "repair" it in the same way you repaired the other scripts?
Thanks in advance, 
Ralf

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 4 months ago #239184 by tpartner
Try this (untested):

Code:
<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>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: ralfkunze

Please Log in to join the conversation.

  • ralfkunze
  • ralfkunze's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 year 4 months ago #239187 by ralfkunze
Wow, thank you SO much! It works, everything is fine!

Wish you a merry christmas! 
Ralf

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose