Welcome to the LimeSurvey Community Forum

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

Array numbers with checkbox and an exclusive option

  • eloner
  • eloner's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
8 years 9 months ago #121722 by eloner
Hello,
I have a question like that:



(type: array numbers with checkbox).

and the following subquestions:



I need to set LimeSurvey in order to uncheck all the flags on a row if "I don't know" is chosen.
How can I set this condition?
I tried to insert SQ004 (the code for "I don't know") in the field "Exclusive option" (Advanced settings), but it doesn't work...
Am I missing something?
Here is the question code:

File Attachment:

File Name: limesurvey...3347.lsq
File Size:6 KB


Thanks to everybody for the help!
Elo






P.S. I use LS Version 2.05+ Build 150520
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 9 months ago #121732 by holch
Have a look here: I think this describe exactly your problem:
www.limesurvey.org/en/community-services...e-of-these-exclusion

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The following user(s) said Thank You: eloner
The topic has been locked.
  • eloner
  • eloner's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
8 years 9 months ago #121740 by eloner
Thank you Holch,
I used the workaround manual.limesurvey.org/Workarounds:_Manip..._Excludes_All_Others to my question, but apparently it doesn't work.
What I require is:
- to uncheck all the first options of a row if I choose the last
- to uncheck the last option of a row if a choose one of the first
I enclose a copy of the question with the javascript added according to Tony Partner's workaround:

File Attachment:

File Name: limesurvey...47-2.lsq
File Size:9 KB

(I use the default standard template).
Cheers,
Elo
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 9 months ago - 8 years 9 months ago #121763 by tpartner
Hmm...it seems that there was a typo in that workaround which I have fixed.

Here it is with the typo fixed and support for relevance:

Code:
<script type="text/javascript" charset="utf-8">
  $(document).ready(function() {
    // Call the exclude function using question ID
    excludeOpt({QID});
  });
 
  // A function to make the last option in each array row exclusive
  function excludeOpt (qID) {
 
    var thisQuestion = $('#question'+qID)
 
    // Add some classes to the checkbox cells
    $('td.checkbox-item', thisQuestion).addClass('normalOpt');
    $('tr.subquestions-list', thisQuestion).each(function(i) {
      $('.normalOpt:last', this).removeClass('normalOpt').addClass('exlusiveOpt')
    });
 
    // A listener on the checkbox cells
    $('td.checkbox-item', thisQuestion).click(function (event) {
      handleExclusive($(this));
    });
 
    // A listener on the checkboxes
    $('td.checkbox-item input[type="checkbox"]', thisQuestion).click(function (event) {
      handleExclusive($(this).closest('td'));
    });
 
    function handleExclusive(thisCell) {
 
      var thisRow = $(thisCell).closest('tr');
 
      // Uncheck the appropriate boxes in a row
      if ($(thisCell).hasClass('normalOpt')) {
        $('.exlusiveOpt input[type="checkbox"]', thisRow).attr('checked', false);
      }
      else {
        $('.normalOpt input[type="checkbox"]', thisRow).attr('checked', false);
      }
 
      // Check conditions (relevance)
      $('td.checkbox-item', thisRow).each(function(i) {
        var thisValue = '';
        if($('input[type="checkbox"]', this).is(':checked')) {
          thisValue = 1;
        }
        var thisSGQA = $('input[type="checkbox"]', this).attr('id').replace(/cbox_/, '');
 
        $('input[type="hidden"]', thisRow).attr('value', 'thisValue');
        fixnum_checkconditions(thisValue, thisSGQA, 'hidden');
      });
    }
  }
</script>

Here's a sample survey with some added questions to display relevance functionality:

File Attachment:

File Name: limesurvey...1451.lss
File Size:22 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 8 years 9 months ago by tpartner.
The following user(s) said Thank You: eloner
The topic has been locked.
  • eloner
  • eloner's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
8 years 9 months ago - 8 years 9 months ago #121764 by eloner
Now it works perfectly!
Thank you Tony!
And... you can evaluate the quality of a program also from the quality of the answers you get to your doubts and questions! ;)
Cheers,
Elo

P.S. I have written an e-mail about a donation to LimeSurvey. As soon as we get a response we can send our contribution to the project
Last edit: 8 years 9 months ago by eloner. Reason: typos in editing
The following user(s) said Thank You: tpartner
The topic has been locked.
More
8 years 9 months ago #121845 by david2013
What if I want exclusive option for each column instead of each row. Do we have a workaround too?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 9 months ago #121847 by tpartner
David, use this to make the last row exclusive:

Code:
<script type="text/javascript" charset="utf-8">
  $(document).ready(function() {
    // Call the exclude function using question ID
    excludeOpt({QID});
  });
 
  // A function to make the last option in each array row exclusive
  function colExcludeOpt (qID) {
 
    var thisQuestion = $('#question'+qID)
 
    // Add some classes to the checkbox cells
    $('td.checkbox-item', thisQuestion).addClass('normalOpt');
    $('tr.subquestions-list:last td.checkbox-item', thisQuestion).removeClass('normalOpt').addClass('exlusiveOpt')
 
    // And some column-specific attributes
    $('tr.subquestions-list', thisQuestion).each(function(i){
      $('td.answer-item', this).each(function(i){
        $(this).attr('data-column', i+1);
      });
    });
 
    // A listener on the checkbox cells
    $('td.checkbox-item', thisQuestion).click(function (event) {
      handleColExclusive($(this));
    });
 
    // A listener on the checkboxes
    $('td.checkbox-item input[type="checkbox"]', thisQuestion).click(function (event) {
      handleColExclusive($(this).closest('td'));
    });
 
    function handleColExclusive(thisCell) {
 
      var thisColumn = $(thisCell).attr('data-column');
 
      // Uncheck the appropriate boxes in a row
      if ($(thisCell).hasClass('normalOpt')) {
        $('.exlusiveOpt[data-column="'+thisColumn+'"] input[type="checkbox"]', thisQuestion).attr('checked', false);
      }
      else {
        $('.normalOpt[data-column="'+thisColumn+'"] input[type="checkbox"]', thisQuestion).attr('checked', false);
      }
 
      // Check conditions (relevance)
      $('td.checkbox-item[data-column="'+thisColumn+'"]', thisQuestion).each(function(i) {
        var thisValue = '';
        if($('input[type="checkbox"]', this).is(':checked')) {
          thisValue = 1;
        }
        var thisSGQA = $('input[type="checkbox"]', this).attr('id').replace(/cbox_/, '');
 
        $('input[type="hidden"]', this).attr('value', 'thisValue');
        fixnum_checkconditions(thisValue, thisSGQA, 'hidden');
      });
    }
  }
</script>

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: david2013
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 9 months ago #121848 by tpartner
eloner, I found a small bug that may affect conditional questions. Please use this revised code:

Code:
<script type="text/javascript" charset="utf-8">
  $(document).ready(function() {
    // Call the exclude function using question ID
    excludeOpt({QID});
  });
 
  // A function to make the last option in each array row exclusive
  function excludeOpt (qID) {
 
    var thisQuestion = $('#question'+qID)
 
    // Add some classes to the checkbox cells
    $('td.checkbox-item', thisQuestion).addClass('normalOpt');
    $('tr.subquestions-list', thisQuestion).each(function(i) {
      $('.normalOpt:last', this).removeClass('normalOpt').addClass('exlusiveOpt')
    });
 
    // A listener on the checkbox cells
    $('td.checkbox-item', thisQuestion).click(function (event) {
      handleExclusive($(this));
    });
 
    // A listener on the checkboxes
    $('td.checkbox-item input[type="checkbox"]', thisQuestion).click(function (event) {
      handleExclusive($(this).closest('td'));
    });
 
    function handleExclusive(thisCell) {
 
      var thisRow = $(thisCell).closest('tr');
 
      // Uncheck the appropriate boxes in a row
      if ($(thisCell).hasClass('normalOpt')) {
        $('.exlusiveOpt input[type="checkbox"]', thisRow).attr('checked', false);
      }
      else {
        $('.normalOpt input[type="checkbox"]', thisRow).attr('checked', false);
      }
 
      // Check conditions (relevance)
      $('td.checkbox-item', thisRow).each(function(i) {
        var thisValue = '';
        if($('input[type="checkbox"]', this).is(':checked')) {
          thisValue = 1;
        }
        var thisSGQA = $('input[type="checkbox"]', this).attr('id').replace(/cbox_/, '');
 
        $('input[type="hidden"]', this).attr('value', 'thisValue');
        fixnum_checkconditions(thisValue, thisSGQA, 'hidden');
      });
    }
  }
</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
5 years 10 months ago #168850 by stephanied
I would like to implement this code on version 2.73.1
The goal is to uncheck "no involvement" if any of the other options in a column are selected and uncheck the all other options in a column once "no involvement" is selected.

If we could take it another further step by disabling selections per column after "no involvement" is selected, that would be great, but it's not needed.

I have attached a photo of my current question layout -- Array(numbers)
Attachments:
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 10 months ago #168859 by tpartner
Can you attach a small sample survey?

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 10 months ago #168862 by stephanied
Unfortunately I cannot publicly post a sample survey, however, I can personal message you a link.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 10 months ago #168864 by tpartner
A link to a survey does not help with development and I don't have time to create test surveys for everyone.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose