Welcome to the LimeSurvey Community Forum

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

Set an exclusive answer in Array/Multi flexi/Checkbox type question

  • ines_azalmeida
  • ines_azalmeida's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 8 months ago #156406 by ines_azalmeida
Hello,

This is my Array / Multi-flexi type question, where instead of numbers, I'm using checkboxes.



I'm having some problems setting LimeSurvey to uncheck all the flags if the first column "Não possui qualquer tipo de software" (which means something like "none") is choosen. So, what I want is to uncheck all the options of a row if I choose the first one and to uncheck the first option if I select another one.

I used the workaround manual.limesurvey.org/Workarounds:_Manip..._Excludes_All_Others to my question, but apparently it doesn't work.

I'm using LS 2.62.0+170124

Thanks everyone for the help!
Attachments:
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 8 months ago #156440 by tpartner
That workaround ( manual.limesurvey.org/Workarounds:_Manip..._Excludes_All_Others ) DOES work in the latest LTS version.

Here is a working survey modified so the first column is exclusive.

File Attachment:

File Name: limesurvey...9566.lss
File Size:19 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.
  • ines_azalmeida
  • ines_azalmeida's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 8 months ago #156450 by ines_azalmeida
So the only thing I have to do is place that script in the source of the array question, right? Because I've done it and it's not working.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 8 months ago #156454 by tpartner
Yes, first set up your survey to use JavaScript and place the script from my working sample in the source of the array question.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • ines_azalmeida
  • ines_azalmeida's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 8 months ago #156456 by ines_azalmeida
Yes, I have setted up my survey to use JavaScript, but when I place the following script, it doesn't block the other possible answers.

<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:first', 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>
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 8 months ago #156457 by tpartner
Did you try the supplied sample survey? It works for me on all browsers.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • ines_azalmeida
  • ines_azalmeida's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 8 months ago #156458 by ines_azalmeida
Yes and it's not working and I've tried in all the browsers too.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 8 months ago #156459 by tpartner
Sorry, I cannot debug what is happening on your server.

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