How to set conditions for dropdown in a multiple short text ?

Plus d'informations
il y a 5 mois 3 semaines #185718 par SherriChen
Hello,

I have a multiple short text question and I changed one of the subquestions into the dropdown format.
For example:
SQ001: Text
SQ002: Text
SQ003: dropdown (Select 1, select 2, select 3)
SQ004: Text

I want to make SQ004 only show when respondents choose "select 3" in SQ003.
I tried to set conditions for SQ004, it works. But it has a problem. When I choose "select 3", it does not show SQ004 automatically, but when I click "next", it alerts me that SQ004 is not answered. At that time, SQ004 shows.
Can I make SQ004 show automatically after I choose "select 3" in SQ003?
Thank you for your help.

Connexion ou Créer un compte pour participer à la conversation.

LimeSurvey Partners
Plus d'informations
il y a 5 mois 2 semaines #185720 par DenisChenu
Can you show a screen shot of survey logic file ?
Or send a lss
And inform us of your LimeSurvey version …

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
An error happen ? Before make a new topic : remind the Debug mode .

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 5 mois 2 semaines - il y a 5 mois 2 semaines #185729 par tpartner
How did you change one of the subquestions into the dropdown format? With JavaScript? If so, can you attach that script or, even better as Denis suggests, attach a small sample survey (.lss file) containing only the relevant question.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com
Dernière édition: il y a 5 mois 2 semaines par tpartner.
Les utilisateur(s) suivant ont remercié: DenisChenu

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 5 mois 2 semaines #185732 par SherriChen
Here is the sample survey. I want to make SQ005 show only when people choose "Other education level" in SQ004. I use LS 3.17.5. Thank you for your help.

Fichier attaché :

Nom du fichier : limesurvey...2665.lss
Taille du ficher :23 ko
Pièces jointes :

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 5 mois 2 semaines #185733 par Joffm
Hi,

try to test for the text "Other education level" instaed of code "15"

Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 5 mois 2 semaines #185736 par SherriChen
Hi Joffm,

Thank you for your reply. I have tried, but it doesn't work.

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 5 mois 2 semaines #185737 par Joffm
Hi,
It was a guess, because your survey doesn't show the drop-down here (Version 3.17.4+190529)
And in another survey with javascript drop-downs it was like this; that you had to use the labels.

Sorry
Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 5 mois 2 semaines #185738 par tpartner
The problem is that Expression Manager is not being fired by the "change" or "keyup" events (I don't know why).

Use this script to insert the drop-down:

<script type="text/javascript" charset="utf-8">
	$(document).on('ready pjax:complete',function()	{
		var qID = {QID};		
		var inputNum = 4;
 
		// Define the select element (dropdown)
		var prov1 = '<select id="prov1" class="form-control">\
						<option value="">--Choose education level--</option>\
						<option value="1">Primary education</option>\
						<option value="2">Pre-vocational secondary education (VMBO)</option>\
						<option value="3">Senior general secondary education (HAVO) substructure (Year 1-3)</option>\
						<option value="4">Senior general secondary education (HAVO) (Year 4-5)</option>\
						<option value="5">Senior general secondary education (HAVO) (Year 1-5)</option>\
						<option value="6">Pre-university education (VWO) substructure (Year 1-3)</option>\
						<option value="7">Pre-university education (VWO) (Year 4-6) </option>\
						<option value="7">Pre-university education (VWO) (Year 1-6) </option>\
						<option value="8">MBO Level 1</option>\
						<option value="9">MBO level 2-4</option>\
						<option value="10">Higher professional education (HBO) bachelor</option>\
						<option value="11">Higher professional education (HBO) master</option>\
						<option value="12">University education (WO) bachelor</option>\
						<option value="13">University education (WO) master</option>\
						<option value="14">University education (WO) doctor</option>\
						<option value="15">Other education level</option>\
					</select>';
 
		// Hide the text input
		$('#question'+qID+' .question-item:eq('+(inputNum-1)+') input[type="text"]').hide();
 
		// Insert the select elements
		if($('#question'+qID+' .question-item:eq('+(inputNum-1)+') select').length == 0) {
			$('#question'+qID+' .question-item:eq('+(inputNum-1)+') input[type="text"]').before(prov1);
		}		
 
		// Initially select an option if the question has already been answered
		$('#question'+qID+' select').each(function(i) {
			if($.trim($(this).next('input[type="text"]').val()) != '') {
				$(this).val($.trim($(this).next('input[type="text"]').val()));
			}
		});
 
		// Listener on the dropdowns - insert selected values into hidden text input
		$('#question'+qID+' select').change(function() {
			var thisInput = $(this).next('input[type="text"]');
			$(thisInput).val($(this).val());
			checkconditions($(thisInput).attr('value'), $(thisInput).attr('name'), 'text');
		});
 
		// Some styles
		$('#question'+qID+' select').css({
		'margin':'0.3em 0 0 0'
		});
	});
</script>

Working survey attached:

Fichier attaché :

Nom du fichier : limesurvey...6651.lss
Taille du ficher :24 ko

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com
Pièces jointes :

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 5 mois 2 semaines #185739 par SherriChen
Hi,

I try to delete the first subquestion(SQ001 with the date button), it works. So I guess, maybe there is something wrong with my script. I don' t know much about Javascript. Can you help to check it? Thank you.

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 5 mois 2 semaines #185742 par SherriChen
WOW! Perfect! It works well. Thank you very much for your help!

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 5 mois 2 semaines #185743 par DenisChenu

tpartner écrit: The problem is that Expression Manager is not being fired by the "change" or "keyup" events (I don't know why).

Because event is attached to .select-item select or .dropdown-item select

See github.com/LimeSurvey/LimeSurvey/blob/e2...em_javascript.js#L38


Alternate solution
$('#question'+qID+' .question-item:eq('+(inputNum-1)+') input[type="text"]').hide().closest(".answer-item").addClass("dropdown-item");

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
An error happen ? Before make a new topic : remind the Debug mode .

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 5 mois 2 semaines #185745 par SherriChen

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 5 mois 2 semaines #185746 par tpartner
There should also be keyup events attached to the original (now hidden) text input. No?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 5 mois 2 semaines #185749 par DenisChenu

tpartner écrit: There should also be keyup events attached to the original (now hidden) text input. No?

Yes right …
github.com/LimeSurvey/LimeSurvey/blob/e2...em_javascript.js#L27

Then maybe it can work with updating
// Listener on the dropdowns - insert selected values into hidden text input
		$('#question'+qID+' select').change(function() {
			$(this).next('input[type="text"]').val($(this).val()).trigger('change');
		});
to
// Listener on the dropdowns - insert selected values into hidden text input
		$('#question'+qID+' select').change(function() {
			$(this).next('input[type="text"]').val($(this).val()).trigger('keyup');
		});

PS @tpartner : .answer-item :text BUT .dropdown-item select . Unsure : maybe .answer-item select ?
But maybe too : remove Class usage , and use select[data-em] or something siilar (have issue with Question Theme or Question plugins about css usage and EM)

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
An error happen ? Before make a new topic : remind the Debug mode .

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 5 mois 2 semaines #185751 par tpartner
Yep, I tried keyup, that didn't work either. (I suspect something to do with the first date workaround applied)

As far as I know, my solution works.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com

Connexion ou Créer un compte pour participer à la conversation.

Commencez dès maintenant !

Créez simplement un compte et commencez à utiliser LimeSurvey dès aujourd'hui.

Inscrivez-vous maintenant

Inscrivez-vous à notre Newsletter!