Welcome to the LimeSurvey Community Forum

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

Cannot skip group due to pre-populated dropdown list

  • iipumarrifai
  • iipumarrifai's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 1 week ago #196894 by iipumarrifai
Hi, I have dropdown field that populated using external database via json, it works on Limesurvey 1.x but when I imported to Limsurvey 4, the dropdown works but we cannot skip the group questions because it said I can't move to next group until I entered correct value for those dropdown field.

I attach the screenshot of the form.

Thanks in advance,

-iip-
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 1 week ago #196901 by tpartner
What is the script you are using to populate the dropdowns?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • iipumarrifai
  • iipumarrifai's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 1 week ago #196902 by iipumarrifai
Replied by iipumarrifai on topic Cannot skip group due to pre-populated dropdown list
I'm using

$.getJSON(url,function(data){
$(data).each(function(i,item){
myVar.append(
$('<option></option>').val(item).html(item)
)
}
});

The dropdown list seems ok, the value populated correctly, but I can't move to the next group even all variable set as not mandatory. It stuck on this group of questions.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 1 week ago #196906 by tpartner
You cannot dynamically add answers to a list-dropdown question - the answers mst be defined in the admin GUI.

I would suggest using a short-text type question and insert a custom select (drop-down) element to populate it.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • iipumarrifai
  • iipumarrifai's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 1 week ago #196907 by iipumarrifai
Replied by iipumarrifai on topic Cannot skip group due to pre-populated dropdown list
Hi Tony, how to insert custom dropdown on short-text type question ? Could you show me an example to do that?

Thanks in advance,
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 1 week ago #196910 by tpartner
This script will insert a <select> element into a short-text question.

Code:
<script type="text/javascript" charset="utf-8">
 
  $(document).on('ready pjax:scriptcomplete',function(){
 
    // Identify this question
    var thisQuestion = $('#question{QID}');
 
    // Insert the selectelement
    if($('.answer-item:eq(0) .inserted-select', thisQuestion).length == 0) {
      $('.answer-item:eq(0)', thisQuestion).addClass('with-select').append('<select id="inserted-select-{QID}" class="inserted-select form-control list-question-select">\
        <option value="">Please choose...</option>\
        <option value="Yes">Yes</option>\
        <option value="No">No</option>\
        <option value="Do not know">Do not know</option>\
      </select>');
    } 
 
    // Listeners on select elements
    $('#inserted-select-{QID}').on('change', function(i) {
      if($(this).val() != '') {
        $(this).closest('.answer-item').find('input:text').val($.trim($('option:selected', this).text())).trigger('change');
      }
      else {
        $(this).closest('.answer-item').find('input:text').val('').trigger('change');
      }
    });
 
    // Returning to page
    var inputText = $.trim($('input:text:eq(0)', thisQuestion).val());
    $('select.inserted-select', thisQuestion).val(inputText);
 
    // Clean-up styles
    $('select.inserted-select', thisQuestion).css({
      'width': 'auto',
      'max-width': '100%'
    });
    $('.with-select input:text', thisQuestion).css({
      'position': 'absolute',
      'left': '-9999em'
    });
  });
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...3813.lss
File Size:20 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • iipumarrifai
  • iipumarrifai's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 1 week ago #196911 by iipumarrifai
Replied by iipumarrifai on topic Cannot skip group due to pre-populated dropdown list
Tank you Tony,

This is really helpful, since you told me we cannot populate dropdown, I just trying to add the option into the question directly, it seems worked.
Choose car type:
<br><br>
<select style="width: 300px;" id="cars" class="form-control list-question-select">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>

<script type="text/javascript" charset="utf-8">
....
....

I just have to modify my script to adapt this new behaviour.

Thank you verymuch,

-iip-
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 1 week ago - 4 years 1 week ago #196914 by tpartner

This is really helpful, since you told me we cannot populate dropdown

I said "You cannot dynamically add answers to a list-dropdown question". You can dynamically modify a <select> element that you insert into a text-short (or array) via JavaScript.

That's the whole point of this exercise - to be able to add options via an AJAX call.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 4 years 1 week ago by tpartner.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose