List with Comment - Show text box ONLY when option "Non-Applicable" is selected

More
2 months 1 day ago #203165 by teracomp
Is it possible to show the textarea only when a certain answer is clicked? Is there some javascript that can be loaded at the beginning of the survey that applies to all questions that have a List with Comment type question with an answer option of "Non-Applicable"?

Dave Phillips

Please Log in to join the conversation.

LimeSurvey Partners
More
2 months 1 day ago #203175 by holch
How about using the "other" option and rename it to "non-applicable"?

Or you use a second question with a relevance equation.

I am sure it is doable with JS as well, but that is with others.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

Please Log in to join the conversation.

More
2 months 1 day ago #203180 by teracomp
That's a great idea, but when I use Bootstrap Buttons, the "Label for 'Other:' option" is not used. In other words, I entered "Not Applicable" as the 'Other' label, but it only works with Radio Buttons, not Bootstrap Buttons.

Dave Phillips

Please Log in to join the conversation.

More
2 months 21 hours ago #203184 by tpartner
Sure we can do that with JS.

Can you attach a small sample survey (.lss file) containing only one question.

Give the "Non-Applicable" option a unique code that would only be found in these custom questions so they can be identified by JS.

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 21 hours ago #203185 by teracomp
I've attached a lss file with one question. The entire survey is built using this question type (list with comment), so a solution here will be greatly appreciated.

Dave Phillips
Attachments:

Please Log in to join the conversation.

More
1 month 4 weeks ago - 1 month 4 weeks ago #203210 by tpartner
If you want to apply it to all list-with-comment questions that have (for example) and answer code "NA", add this function to the end of your survey theme custom.js file.

(I assumed that you want the textarea cleared when hidden)

$(document).on('ready',function(){
	$('.list-with-comment').each(function(i) {
 
		var naCode = 'NA';
 
		var thisQuestion = $(this);
		var qID = thisQuestion.attr('id').replace(/question/, '');
		var $naInput = $('input:radio[id$="X'+qID+naCode+'"]', thisQuestion);
 
		if($naInput.length > 0) {
			// Hide the textarea
			if(!$naInput.is(':checked')) {
				$('.answer-item.text-item', thisQuestion).hide();
			}
 
			// Listener on the radios
			$('input:radio', thisQuestion).on('click', function(e) {
				if($(this).is($naInput)) {
					// Show the textarea
					$('.answer-item.text-item', thisQuestion).fadeIn(500);
				}
				else {
					// Hide the textarea
					$('.answer-item.text-item', thisQuestion).fadeOut(500, function(e) {
						$('.answer-item.text-item textarea', thisQuestion).val('').trigger('keyup');
					});
				}
			});
		}
	});
});

Here is your sample survey back with that function in a script in the source of the first question:

File Attachment:

File Name: limesurvey...5(1).lss
File Size:17 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:
Last edit: 1 month 4 weeks ago by tpartner.
The following user(s) said Thank You: teracomp

Please Log in to join the conversation.

More
1 month 4 weeks ago #203214 by teracomp
This looks awesome! Thanks (again) -- as always. I'll implement this as you suggested -- custom.js.

Dave Phillips

Please Log in to join the conversation.

More
1 month 4 weeks ago #203227 by DenisChenu

teracomp wrote: That's a great idea, but when I use Bootstrap Buttons, the "Label for 'Other:' option" is not used. In other words, I entered "Not Applicable" as the 'Other' label, but it only works with Radio Buttons, not Bootstrap Buttons.

It can be reported as a issue in my opinion.

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 . I don't answer to private message.

Please Log in to join the conversation.

More
1 month 4 weeks ago #203235 by teracomp
Thanks for the advice and confirmation. I'll report the issue.

Dave Phillips

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now