Welcome to the LimeSurvey Community Forum

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

Unsaved answear when adding dropdown menu into array number question

  • f.caldura
  • f.caldura's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 1 week ago #243006 by f.caldura
Please help us help you and fill where relevant:
Your LimeSurvey version: Version 3.27.31+220104
Own server or LimeSurvey hosting: hosting
==================
Hello everyone,

i have a tricky question,
i found this code for adding dropdown menu in array number question, and it worked!
My concern is that:
if for some reason the respondent shifts to another page of the questionary or forgots to answear some question and moves forward. all the selection in the dropdown menus he made are lost.  Even if he save the answers, the selection he made are lost. This doesn't happen in the same question when the respondent write some numbers,

Is there any solution?

I attach lss file
down here the code I found:

<script type="text/javascript" charset="utf-8">
  $(document).on('ready pjax:scriptcomplete',function(){
    var thisQuestion = $('#question{QID}');
 
    // Insert selects
    $('.answer-item.answer_cell_EDGEN', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\
  <option value="">...</option>\
  <option value="1">Femmina</option>\
  <option value="2">Maschio</option>\
</select>');
    $('.answer-item.answer_cell_EDRLAV', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\
  <option value="">...</option>\
  <option value="1">A tempo indeterminato </option>\
  <option value="2">A tempo determinato </option>\
  <option value="3">Contratto di collaborazione professionale (partita Iva)</option>\
  <option value="4">Co.Co.Co./a progetto</option>\
  <option value="5">Somministrati,agenzie interinali,accordi con cooperative</option>\
  <option value="6">Educatore-socio/Educatore-titolare</option>\
  <option value="6">Altro rapporto di lavoro</option>\
</select>');
    $('.answer-item.answer_cell_EDSTUD', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\
  <option value="">...</option>\
  <option value="1">Attestato di qualifica rilasciato dal sistema della formazione professionale</option>\
  <option value="2">Diploma di scuola superiore afferente all’area psico-pedagogica</option>\
  <option value="3">Laurea (di I livello o II livello) afferente all’area psico-pedagogica</option>\
  <option value="4">Laurea umanistica o sociale e master avente oggetto la formazione per la prima infanzia</option>\
  <option value="5">Altri titoli di studio (Laurea, Diploma, ecc.) non afferenti all’area psico-pedagogica</option>\
  <option value="6">Altro titolo di studio</option>\
</select>');
    $('.answer-item.answer_cell_EDEXP', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\
  <option value="">...</option>\
  <option value="1">Fino a 2 anni</option>\
  <option value="2">3-5 anni</option>\
  <option value="3">Oltre 5 anni</option>\
</select>');
    $('.answer-item.answer_cell_EDANZ', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\
  <option value="">...</option>\
  <option value="1">Fino a 3 mesi</option>\
  <option value="2">3-6 mesi</option>\
  <option value="3">7-12 mesi</option>\
  <option value="4">Da 1 a 2 anni</option>\
  <option value="5">Da 2 a 5 anni</option>\
  <option value="6">Oltre 5 anni</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');
      }
    });
    $('.with-select input:text', thisQuestion).css({
      'position': 'absolute',
      'left': '-9999em'
    });
  });
</script>

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 1 week ago - 1 year 1 week ago #243008 by Joffm
Hi,
I do not know where you found this script, but in the script a big part is missing
After you define your drop-downs it should be this

Code:
    // 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);
    });
 
   // Clean-up styles
    $('select.inserted-select', thisQuestion).css({
      'max-width': '100%'
    });
    $('.with-select input:text', thisQuestion).css({
      'position': 'absolute',
      'left': '-9999em'
    });
  });
</script>


Furthermore you have quotes around your "valdation equation"
'{PE2_EDETA.NAOK.max_num}<=40' and '{PE2_EDORE.NAOK.num_range(18,73)}'
You see that it is not recognized as equation (gray color)
 
See the manual:
[url] manual.limesurvey.org/ExpressionScript_-...#Syntax_highlighting [/url]
gray text is just a text.

And you use curly brackets, though the curly brackets already are symbolized to show that in this case they are not necessary
 

Then you use two properties ".max_num" and ".num_range". Where did you find them?
With the correct syntax (no quotes, no curly brackets) both are shown as error
 

So there are many mistakes

Joffm

And in my opinion you should revise the question.
Even if you narrow the subquestion label field everything is really noarrow.
Maybe baetter to use several questions of type "multiple text".
Here you also can insert drop-downs, different field widths, etc

 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 year 1 week ago by Joffm.

Please Log in to join the conversation.

  • f.caldura
  • f.caldura's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 1 week ago #243026 by f.caldura
Dear Joffn,

thankyou for all the work you put in for this community and for helping me.
As you noticed there are three different problems:

the code: you're right! I have permission problem on the server that is why I cut part of the code months ago (i didnt recall it), i'm tryng to solve this with the webmaster.

the validation: yes it's wrong i have to fix it, i found that code somewhere but evidently it doesn't work, (have you some suggestion?)

using another question type: the questionnarie is designed  so that the respondent first gives a numerical input (n: number of educators currently working ect) than for each of the educators the respondent is asked to give some specific information, the numbers of row in the array number question depends on the previous numeric answer. 
I found this solution but i'm not an expert,maybe there is a better one, I really don't knok

thank you,
fc

 

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose