Welcome to the LimeSurvey Community Forum

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

Hide radio button option among condition

  • TomTomT
  • TomTomT's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 2 weeks ago - 3 years 2 weeks ago #227208 by TomTomT
I looked around, there are solutions but none of them worked for me so far. 
I have a survey for which respondents need to confirm informations or correct/fill them. 
I would like to disable the option of clicking "Yes that's true" if the statement is N/A. (here the example would be for the e-mail) see the image below
Thanks in advance
 
Last edit: 3 years 2 weeks ago by TomTomT.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 2 weeks ago #227218 by Joffm
Replied by Joffm on topic Hide radio button option among condition

there are solutions but none of them worked for me so far. 

Which solutions did you try?

I do not see any issue with this script
Code:
<script type="text/javascript" charset="utf-8">
    $(document).on('ready pjax:scriptcomplete',function(){
        // Identify the questions
        var q1ID = {QID};
        var thisQuestion = $('#question'+q1ID);
        var nextQuestion = thisQuestion.nextAll('.multiple-short-txt:eq(0)');
        var q2ID = $(nextQuestion).attr('id').replace(/question/, '');
        
        //Hide the multiple-short-text
        nextQuestion.hide();
        
        // Move the text inputs
        $('tr.answers-list', thisQuestion).each(function(i) {
            var thisCode = $(this).attr('id').split('X')[2].split(q1ID)[1];
            $('td.answer-item:last input[type="radio"]', this).css({
                'position': 'absolute',
                'left': '-9999em'
            });
            $('td.answer-item:last', this).removeClass('radio-item').addClass('inserted-text-item').append($('input[type="text"][id$="X'+q2ID+thisCode+'"]', nextQuestion));
        });
        
        // Listeners on the text inputs
        $('input[type="text"]', thisQuestion).on('keyup change', function(e) {
            var thisRadio = $(this).closest('td').find('input[type="radio"]');
            var thisRadioVal = thisRadio.val();
            if($.trim($(this).val()) != '') {
                $(thisRadio).trigger('click');
            }
            else {
                $(thisRadio).prop('checked', false);
                thisRadioVal = '';
            }
            // Reset Expression manager
            checkconditions(thisRadioVal, $(thisRadio).attr('name'), 'radio', 'click');
        });
        
        // Listeners on the radios
        $('input[type="radio"]', thisQuestion).on('click', function(e) {
            if(!$(this).closest('td').hasClass('inserted-text-item')) {
                $(this).closest('tr').find('input[type="text"]').val('');
            }
        });
 
    });
</script>
 

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

Please Log in to join the conversation.

  • TomTomT
  • TomTomT's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 2 weeks ago #227220 by TomTomT
Replied by TomTomT on topic Hide radio button option among condition
Thanks, your script is working fine but not doing what I am looking for. The picture below is the result I am expecting: (If among the Attributes of the participants there is a N/A, there should be no possibility to click on "Yes" button).
I played around with the CSS:  forums.limesurvey.org/forum/design-issue...-radio-button-circle
and JQuery:  community.qualtrics.com/XMcommunity/disc...ngle-select-question

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 2 weeks ago #227221 by Joffm
Replied by Joffm on topic Hide radio button option among condition
Oh, you did not show this in your first picture

Anyway, why do you use this array?
You could use a multiple short text where the existing values are preset.
So either the respondents leaves as it is or corrects.

Joffm

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

Please Log in to join the conversation.

  • TomTomT
  • TomTomT's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 2 weeks ago #227222 by TomTomT
Replied by TomTomT on topic Hide radio button option among condition
Right, I think I put the wrong picture in the beginning.
Smart suggestion, I still need to use the array as they need to interact with each question (instead of validating without really checking)

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 2 weeks ago #227234 by tpartner
Replied by tpartner on topic Hide radio button option among condition
Can you attach a small sample survey (.lss file) containing only the relevant question(s)?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

  • TomTomT
  • TomTomT's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 2 weeks ago #227264 by TomTomT
Replied by TomTomT on topic Hide radio button option among condition
Here you go

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 2 weeks ago #227267 by tpartner
Replied by tpartner on topic Hide radio button option among condition
The attached survey does not resemble your screenshot. It has only one array column and no code to insert the radio elements.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

  • TomTomT
  • TomTomT's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 2 weeks ago #227269 by TomTomT
Replied by TomTomT on topic Hide radio button option among condition
My apologies, I exported an old test survey.
Here is the one that is in my picture. The name doesn't appear because it calls for the imported attributes of participants
Thanks

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 2 weeks ago #227278 by tpartner
Replied by tpartner on topic Hide radio button option among condition
You can use JavaScript to detect the "N/A" string in the row label and, if found, remove the first-column radio element.

Code:
<script type="text/javascript" data-author="Tony Partner">
  $(document).on('ready pjax:scriptcomplete',function(){
    // Identify the questions
    var q1ID = {QID};
    var thisQuestion = $('#question'+q1ID);
    var nextQuestion = thisQuestion.nextAll('.multiple-short-txt:eq(0)');
    var q2ID = $(nextQuestion).attr('id').replace(/question/, '');
 
    //Hide the multiple-short-text
    nextQuestion.hide();
 
    // Move the text inputs
    $('tr.answers-list', thisQuestion).each(function(i) {
      var thisCode = $(this).attr('id').split('X')[2].split(q1ID)[1];
      $('td.answer-item:last input[type="radio"]', this).css({
        'position': 'absolute',
        'left': '-9999em'
      });
      $('td.answer-item:last', this).removeClass('radio-item').addClass('inserted-text-item').append($('input[type="text"][id$="X'+q2ID+thisCode+'"]', nextQuestion));
    });
 
    // Listeners on the text inputs
    $('input[type="text"]', thisQuestion).on('keyup change', function(e) {
      var thisRadio = $(this).closest('td').find('input[type="radio"]');
      var thisRadioVal = thisRadio.val();
      if($.trim($(this).val()) != '') {
        $(thisRadio).trigger('click');
      }
      else {
        $(thisRadio).prop('checked', false);
        thisRadioVal = '';
      }
      // Reset Expression manager
      checkconditions(thisRadioVal, $(thisRadio).attr('name'), 'radio', 'click');
    });
 
    // Listeners on the radios
    $('input[type="radio"]', thisQuestion).on('click', function(e) {
      if(!$(this).closest('td').hasClass('inserted-text-item')) {
        $(this).closest('tr').find('input[type="text"]').val('');
      }
    });
 
    // Remove the first-column radio if "N/A" is found in row label
    var removeString = 'N/A';
    $('tr[id^="javatbd"]', thisQuestion).each(function(i) {
      if($('.answertext:eq(0)', this).text().includes(removeString)) {
        $('.answer-item:eq(0) *', this).remove();
      }
    });
  });
</script>

 

Sample survey attached (with hard-coded "N/A" in the third sub-question): 

File Attachment:

File Name: limesurvey...8544.lss
File Size:25 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: TomTomT

Please Log in to join the conversation.

  • TomTomT
  • TomTomT's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 1 week ago #227380 by TomTomT
Replied by TomTomT on topic Hide radio button option among condition
Thanks So much!
It works perfectly!

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose