Cannot skip group due to pre-populated dropdown list

More
2 months 3 weeks 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-
Attachments:

Please Log in to join the conversation.

LimeSurvey Partners
More
2 months 3 weeks 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.
Official LimeSurvey Partner - partnersurveys.com

Please Log in to join the conversation.

More
2 months 3 weeks ago #196902 by iipumarrifai
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.

Please Log in to join the conversation.

More
2 months 3 weeks 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.
Official LimeSurvey Partner - partnersurveys.com

Please Log in to join the conversation.

More
2 months 3 weeks ago #196907 by iipumarrifai
Hi Tony, how to insert custom dropdown on short-text type question ? Could you show me an example to do that?

Thanks in advance,

Please Log in to join the conversation.

More
2 months 3 weeks ago #196910 by tpartner
This script will insert a <select> element into a short-text question.

<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.
Official LimeSurvey Partner - partnersurveys.com
Attachments:

Please Log in to join the conversation.

More
2 months 3 weeks ago #196911 by iipumarrifai
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-

Please Log in to join the conversation.

More
2 months 3 weeks ago - 2 months 3 weeks 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.
Official LimeSurvey Partner - partnersurveys.com
Last edit: 2 months 3 weeks ago by tpartner.

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now