- Posts: 162
- Thank you received: 14
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
List with Comment - Show text box ONLY when option "Non-Applicable" is selected
- teracomp
- Topic Author
- Offline
- Elite Member
Less
More
3 years 9 months ago #203165
by teracomp
Dave Phillips
List with Comment - Show text box ONLY when option "Non-Applicable" is selected was created 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
The topic has been locked.
- holch
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 11660
- Thank you received: 2742
3 years 9 months ago #203175
by holch
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Replied by holch on topic List with Comment - Show text box ONLY when option "Non-Applicable" is selected
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.
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.
The topic has been locked.
- teracomp
- Topic Author
- Offline
- Elite Member
Less
More
- Posts: 162
- Thank you received: 14
3 years 9 months ago #203180
by teracomp
Dave Phillips
Replied by teracomp on topic List with Comment - Show text box ONLY when option "Non-Applicable" is selected
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
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
3 years 9 months ago #203184
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic List with Comment - Show text box ONLY when option "Non-Applicable" is selected
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.
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.
The topic has been locked.
- teracomp
- Topic Author
- Offline
- Elite Member
Less
More
- Posts: 162
- Thank you received: 14
3 years 9 months ago #203185
by teracomp
Dave Phillips
Replied by teracomp on topic List with Comment - Show text box ONLY when option "Non-Applicable" is selected
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:
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
3 years 8 months ago - 3 years 8 months ago #203210
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic List with Comment - Show text box ONLY when option "Non-Applicable" is selected
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)
Here is your sample survey back with that function in a script in the source of the first question:
(I assumed that you want the textarea cleared when hidden)
Code:
$(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:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 3 years 8 months ago by tpartner.
The following user(s) said Thank You: teracomp
The topic has been locked.
- teracomp
- Topic Author
- Offline
- Elite Member
Less
More
- Posts: 162
- Thank you received: 14
3 years 8 months ago #203214
by teracomp
Dave Phillips
Replied by teracomp on topic List with Comment - Show text box ONLY when option "Non-Applicable" is selected
This looks awesome! Thanks (again) -- as always. I'll implement this as you suggested -- custom.js.
Dave Phillips
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13648
- Thank you received: 2491
3 years 8 months ago #203227
by DenisChenu
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.
Replied by DenisChenu on topic List with Comment - Show text box ONLY when option "Non-Applicable" is selected
It can be reported as a issue in my opinion.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.
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.
The topic has been locked.
- teracomp
- Topic Author
- Offline
- Elite Member
Less
More
- Posts: 162
- Thank you received: 14
3 years 8 months ago #203235
by teracomp
Dave Phillips
Replied by teracomp on topic List with Comment - Show text box ONLY when option "Non-Applicable" is selected
Thanks for the advice and confirmation. I'll report the issue.
Dave Phillips
The topic has been locked.