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
  • teracomp's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
3 years 9 months 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
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 9 months 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.

The topic has been locked.
  • teracomp
  • teracomp's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
3 years 9 months 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
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 9 months 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.
The topic has been locked.
  • teracomp
  • teracomp's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
3 years 9 months 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
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 8 months ago - 3 years 8 months 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)

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:

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.
Last edit: 3 years 8 months ago by tpartner.
The following user(s) said Thank You: teracomp
The topic has been locked.
  • teracomp
  • teracomp's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
3 years 8 months ago #203214 by teracomp
This looks awesome! Thanks (again) -- as always. I'll implement this as you suggested -- custom.js.

Dave Phillips
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 8 months 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.
The topic has been locked.
  • teracomp
  • teracomp's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
3 years 8 months ago #203235 by teracomp
Thanks for the advice and confirmation. I'll report the issue.

Dave Phillips
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose