Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Hide comment box

  • Fabian_Hartleb
  • Fabian_Hartleb's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 months 3 days ago - 3 months 2 days ago #254952 by Fabian_Hartleb
Hide comment box was created by Fabian_Hartleb
Your LimeSurvey version: Lime Survey Version 4.3.15+200907
Own server or LimeSurvey hosting: Own server
Survey theme/template: fruity


Using the multiple answer with comment question type, is there any way to hide the comment boxes until you tick a box. The comment box should only appear for the selected options and stay hidden for all unselected options.

On a seperate note is there a way to create a comment box that unfolds if you manually click on the corresponding button and stays hidden if you dont.

My Javascript knowledge is very limited so I have no idea how to do this. Grateful for any help

 
Last edit: 3 months 2 days ago by Fabian_Hartleb.

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 months 2 days ago #254953 by tpartner
Replied by tpartner on topic Hide comment box
We cannot help if you don't give the details of your LimeSurvey installation (as asked when you first posted).

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: Fabian_Hartleb

Please Log in to join the conversation.

  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 months 2 days ago #254958 by holch
Replied by holch on topic Hide comment box

4.3.15+200907


This installation was last updated in September 2020. So it hasn't received any updates, bug fixes or security updates for well over 3 years. Time for an update, I'd say.

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.

  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 months 2 days ago #254969 by tpartner
Replied by tpartner on topic Hide comment box
Well, I can't do anything with version 4.x but for 5.x this script, placed in the source of a multiple-choice-with-comments question, will hide the text inputs (and delete their values) unless the checkboxes are checked.

Code:
<script type="text/javascript" data-author="Tony Partner">
 
   $(document).on('ready pjax:scriptcomplete',function(){
        var thisQuestion = $('#question{QID}');
 
    // A listener on the checkboxes
    $('input:checkbox', thisQuestion).on('change', function (event) {
            event.stopPropagation();
      handleComment($(this));
    });
 
        // Returning to page
    $('input:checkbox', thisQuestion).each(function (i) {
      handleComment($(this));
    });
 
    function handleComment(thisInput) {
      var thisRow = $(thisInput).closest('li');
 
      if(thisInput.is(':checked')) {
                $('.text-item', thisRow).show();
            }
            else {
                $('.text-item', thisRow).hide();
                var textInput = $('.text-item input.form-control:eq(0)', thisRow);
                $(textInput).val('');
                checkconditions($(textInput).val(), $(textInput).attr('name'), 'text');
      }
    }
    });
</script>

Sample survey attached:  

File Attachment:

File Name: limesurvey...3985.lss
File Size:39 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: Fabian_Hartleb

Please Log in to join the conversation.

  • Fabian_Hartleb
  • Fabian_Hartleb's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 months 4 weeks ago #255125 by Fabian_Hartleb
Replied by Fabian_Hartleb on topic Hide comment box
That works for my version too. Thank you so much !!

Please Log in to join the conversation.

  • Fabian_Hartleb
  • Fabian_Hartleb's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 months 3 weeks ago #255401 by Fabian_Hartleb
Replied by Fabian_Hartleb on topic Hide comment box
I just noticed that the code seems to overwrite the conditions I set. If I use the code in a question where a certain answer is set as a condition for the next question to appear, the next question doesnt appear at all, regardless of the answers before. Is there any way to fix that so the condition works?

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Online
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 months 3 weeks ago #255407 by Joffm
Replied by Joffm on topic Hide comment box
Can you please send a lss export of these relevant questions

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

Please Log in to join the conversation.

  • Fabian_Hartleb
  • Fabian_Hartleb's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 months 3 weeks ago #255409 by Fabian_Hartleb
Replied by Fabian_Hartleb on topic Hide comment box
Sure

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 months 3 weeks ago #255414 by tpartner
Replied by tpartner on topic Hide comment box
This will fix the problem:

Code:
<script type="text/javascript" data-author="Tony Partner">
 
    $(document).on('ready pjax:scriptcomplete',function(){
        var thisQuestion = $('#question{QID}');
 
        // A listener on the checkboxes
        $('input:checkbox', thisQuestion).on('change', function (event) {
            handleComment($(this));
        });
 
        // Returning to page
        $('input:checkbox', thisQuestion).each(function (i) {
            handleComment($(this));
        });
 
        function handleComment(thisInput) {
            var thisRow = $(thisInput).closest('li');
 
            if(thisInput.is(':checked')) {
                $('.text-item', thisRow).show();
            }
            else {
                $('.text-item', thisRow).hide();
                var textInput = $('.text-item input.form-control:eq(0)', thisRow);
                $(textInput).val('');
                checkconditions($(textInput).val(), $(textInput).attr('name'), 'text');
            }
        }
    });
</script>

Sample survey:  

File Attachment:

File Name: limesurvey...7399.lss
File Size:44 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: Fabian_Hartleb

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose