Welcome to the LimeSurvey Community Forum

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

Disable specific boxes (=answer options) in a array question (numbers)

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 5 months ago - 9 years 5 months ago #113905 by tpartner
If there is no filtering in the question and if it is the only array-numbers on the page and you are using the default template, you can try this:

Code:
<script type="text/javascript" charset="utf-8">  
  $(document).ready(function() {
 
    // Some classes and attributes
    $('.array-multi-flexi table.question thead tr > *').each(function(i){
      $(this).attr('data-column', i);
    });
    $('.array-multi-flexi table.question tbody tr').each(function(i){
      $('> *', this).each(function(i){
        $(this).attr('data-column', i);
      });
    });
 
    // Hide unnecessary selects 
    $('.array-multi-flexi table.question tbody tr').each(function(i){
      $('select:visible:lt('+i+')', this).hide();
      $('select:visible:eq(0)', this).hide();
    });
 
    // Remove unecessary rows and columns
    $('.array-multi-flexi table.question tbody tr:last').hide();
    $('.array-multi-flexi th[data-column="1"], td[data-column="1"]').hide();
  });
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 9 years 5 months ago by tpartner.
The following user(s) said Thank You: daveintausend
The topic has been locked.
  • daveintausend
  • daveintausend's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
9 years 5 months ago #113910 by daveintausend
Thanks a lot Tony, with the Default template this indeed seems to work aswell.
The topic has been locked.
More
6 years 10 months ago #155061 by bdeprez
Hi all,

This is a pretty old topic and I think it may no longer work the same... Or I'm doing something wrong (this is the most probable of the both).

I'm trying to hide a radio button in an array

The button I'm trying to hide is the following in my page source:
Code:
<!-- answer_td -->
<td class="answer-cell-3 answer_cell_A1 answer-item radio-item text-center radio">
    <input
        class="radio"
        type="radio"
        name="783318X281X2223SQ001"
        value="A1"
        id="answer783318X281X2223SQ001-A1"
                onclick="checkconditions(this.value, this.name, this.type)"
        aria-labelledby="label-answer783318X281X2223SQ001-A1"
    />
    <label for="answer783318X281X2223SQ001-A1" ></label>
 
    <!--
         The label text is provided inside a div,
         so final user can add paragraph, div, or whatever he wants in the subquestion text
         This field is related to the input thanks to attribute aria-labelledby
    -->
    <div class="visible-xs-block label-text" id="label-answer783318X281X2223SQ001-A1">
        Very Good    </div>
</td>
<!-- end of answer_td -->

This is the script I am using:
Code:
<script type="text/javascript" charset="utf-8">
   $(document).ready(function() {
       $('input.radio[name="783318X281X2223SQ001-A1"]').attr('hidden', 'hidden');
   });
</script>

What am I doing wrong? I tried the 'alert' test just to be sure that my javascript is on and that worked...

Thanks in advance for your help!
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 10 months ago #155070 by tpartner
To avoid manipulating multiple radios, I would use the element ID as a selector. Also, to hide any pseudo-elements, I would hide or remove all of the radio's siblings.

Code:
<script type="text/javascript" charset="utf-8">
   $(document).ready(function() {
       $('#answer783318X281X2223SQ001-A1').closest('.answer-item').find('*').hide();
   });
</script>

Or:

Code:
<script type="text/javascript" charset="utf-8">
   $(document).ready(function() {
       $('#answer783318X281X2223SQ001-A1').closest('.answer-item').find('*').remove();
   });
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
6 years 10 months ago #155072 by bdeprez
Hi tpartner!

thank you very much for your response - I have a quick follow up question...

I had to change my array to an 'Array (numbers)' as I had to allow for multiple boxes to be checked for the same subquestion - that makes that my previous question no longer fits the purpose...

So, now I have 3 questions (X-axis) and 2 answers (Y-axis) which all can be selected with a checkbox.

This is the first "answer row":
Code:
<!-- answer_row -->
<tr id="javatbd783318X281X2231SQ001" class=" well subquestion-list questions-list array2 ">
            <th class="answertext col-xs-12 col-sm-6">
 
 
                    Voice                <input
            type="hidden"
            name="java783318X281X2231SQ001"
            id="java783318X281X2231SQ001"
            value=""
        />
    </th>
 
 
<!-- answer_td_checkboxes -->
<td class="answer-cell-6 answer_cell_SQ001 question-item answer-item  checkbox-item checkbox-item checkbox text-center">
 
    <input
        type="hidden"
        name="java783318X281X2231SQ001_SQ001"
        id="java783318X281X2231SQ001_SQ001"
        value=""
    />
 
    <input
        type="hidden"
        name="783318X281X2231SQ001_SQ001"
        id="answer783318X281X2231SQ001_SQ001"
        value=""
    />
 
    <input
        type="checkbox"
        class="checkbox "
        name="cbox_783318X281X2231SQ001_SQ001"
        id="cbox_783318X281X2231SQ001_SQ001"
                onclick="
            cancelBubbleThis(event);
            aelt=document.getElementById('answer783318X281X2231SQ001_SQ001');
            jelt=document.getElementById('java783318X281X2231SQ001_SQ001');
            if(this.checked)
            {
                aelt.value=1;
                jelt.value=1;
                fixnum_checkconditions(1,'783318X281X2231SQ001_SQ001',aelt.type);
            }
            else
            {
                aelt.value='';
                jelt.value='';
                fixnum_checkconditions('','783318X281X2231SQ001_SQ001',aelt.type);
            }
            return true;"
        onchange="checkconditions(this.value, this.name, this.type)"
        aria-labelledby="label-cbox_783318X281X2231SQ001_SQ001"
        />
 
        <label for="cbox_783318X281X2231SQ001_SQ001"></label>
 
        <!--
             The label text is provided inside a div,
             so final user can add paragraph, div, or whatever he wants in the subquestion text
             This field is related to the input thanks to attribute aria-labelledby
        -->
        <div class="visible-xs-block label-text" id="label-cbox_783318X281X2231SQ001_SQ001">
            Dealer to Dealer (D2D)        </div>
 
    </td>
<!-- end of answer_td_checkboxes -->
 
<!-- answer_td_checkboxes -->
<td class="answer-cell-6 answer_cell_SQ002 question-item answer-item  checkbox-item checkbox-item checkbox text-center">
 
    <input
        type="hidden"
        name="java783318X281X2231SQ001_SQ002"
        id="java783318X281X2231SQ001_SQ002"
        value=""
    />
 
    <input
        type="hidden"
        name="783318X281X2231SQ001_SQ002"
        id="answer783318X281X2231SQ001_SQ002"
        value=""
    />
 
    <input
        type="checkbox"
        class="checkbox "
        name="cbox_783318X281X2231SQ001_SQ002"
        id="cbox_783318X281X2231SQ001_SQ002"
                onclick="
            cancelBubbleThis(event);
            aelt=document.getElementById('answer783318X281X2231SQ001_SQ002');
            jelt=document.getElementById('java783318X281X2231SQ001_SQ002');
            if(this.checked)
            {
                aelt.value=1;
                jelt.value=1;
                fixnum_checkconditions(1,'783318X281X2231SQ001_SQ002',aelt.type);
            }
            else
            {
                aelt.value='';
                jelt.value='';
                fixnum_checkconditions('','783318X281X2231SQ001_SQ002',aelt.type);
            }
            return true;"
        onchange="checkconditions(this.value, this.name, this.type)"
        aria-labelledby="label-cbox_783318X281X2231SQ001_SQ002"
        />
 
        <label for="cbox_783318X281X2231SQ001_SQ002"></label>
 
        <!--
             The label text is provided inside a div,
             so final user can add paragraph, div, or whatever he wants in the subquestion text
             This field is related to the input thanks to attribute aria-labelledby
        -->
        <div class="visible-xs-block label-text" id="label-cbox_783318X281X2231SQ001_SQ002">
            Dealer to Client (D2C)        </div>
 
    </td>
<!-- end of answer_td_checkboxes -->
 
    <!-- right -->
    </tr>
<!-- end of answer_row -->

How would I go and hide the second answer option?

Thank you very much!!!
The topic has been locked.
More
6 years 10 months ago #155073 by bdeprez
Never mind - I just tried out your code above and replaced it with the name of the checkbox and it did the trick!

Thanks again!
The topic has been locked.
More
5 years 1 month ago #181228 by mcovents
I also want to hide a radio button for some subquestions in an array question but it doesn't seem to work.
It does work for checkboxes in an array(numbers) question but I need an array question with radio buttons.
I'm using Limesurvey version 3.15
This is the code that I'm trying to use:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$('input[name="695528X43X1563SQ001_SQ001"]').attr('disabled', 'disabled');
$('input[name="695528X43X1563SQ002_SQ002"]').attr('hidden', 'hidden');
});
</script>
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 1 month ago #181234 by tpartner
Can you attach a small sample survey export (.lss) file containing only the relevant question and describe which radio(s) you are trying to disable?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
5 years 1 month ago #181235 by mcovents
Dear Tony,
In the attached file we have put two questions.
The first one is what we really want: an array with radio buttons however in the first and second row we would like to hide the 3th and 4th option.

After trying several versions, the best we could get is presented in the second question, where we were able to disable (but not hide) check boxes.
However for our current project we need radio buttons, and not check boxes....

Best regards,
Marc
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 1 month ago #181236 by tpartner
It's not a good idea to use the same question codes for the x and y axes - it leads to confusion when trying to identify elements. For this example, I have recoded the Q1 answers (x-axis) to A1-A4.

Rather than hiding the elements, you should remove them so they cannot be selected via the keyboard.

In your example, add something like this to the question source:

Code:
<script type="text/javascript" charset="utf-8">
 
  $(document).ready(function() {
 
    // Remove row 1, answer "A3"
    $('#question{QID} tr.answers-list:eq(0) input:radio[value="A3"]').nextAll('label').remove();
    $('#question{QID} tr.answers-list:eq(0) input:radio[value="A3"]').remove();
 
    // Remove row 1, answer "A4"
    $('#question{QID} tr.answers-list:eq(0) input:radio[value="A4"]').nextAll('label').remove();
    $('#question{QID} tr.answers-list:eq(0) input:radio[value="A4"]').remove();
 
    // Remove row 2, answer "A3"
    $('#question{QID} tr.answers-list:eq(1) input:radio[value="A3"]').nextAll('label').remove();
    $('#question{QID} tr.answers-list:eq(1) input:radio[value="A3"]').remove();
 
    // Remove row 2, answer "A4"
    $('#question{QID} tr.answers-list:eq(1) input:radio[value="A4"]').nextAll('label').remove();
    $('#question{QID} tr.answers-list:eq(1) input:radio[value="A4"]').remove();
  });  
</script>



Sample survey attached:

File Attachment:

File Name: limesurvey...5951.lss
File Size:27 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
5 years 1 month ago #181239 by mcovents
Super!
This is what we were looking for.
Best regards,
Marc
The topic has been locked.
More
5 years 1 month ago #181247 by mcovents
Dear Tony,

Can we ask you another question in the same area?

Do you also have a suggestion how we could remove some input fields in text (and number) arrays in the 3.15 version?

We used this type of question in another survey in which teachers have to indicate when they are available and when not for 6 days of the week (monday-saturday) for three time slots (morning, afternoon and evening).

More specific we used a text array question (example 1 in the attached file), which we further elaborated with a javascript so that they could select their responses from drop down lists (example 2 in attach).

However some of the options are redundant as our school is closed on friday evening as well as on saturday afternoon and evening.

the example is a bit comparable to the example given on

manual.limesurvey.org/Workarounds:_Manip...ation_LS_Version_3.x :

Disable or hide selected fields in a matrix question

We were able to disable options in example 1, but not to remove them. However when we put the extra javascript on it (example 2), also the disable did not work anymore....


As we did not find a sollution to remove those fields we added an extra option "there is no class". It would however be more userfriendly if we could remove the unnecessary fields...


Suggestions would be very welcome, as well for the less complex text (example1) and numer arrays as for the more complex one (example 2)...

Thanks in advance

Marc.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose