- Posts: 77
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Last two exclusive rows numerical matrix
- Mon2016
- Topic Author
- Offline
- Senior Member
Less
More
2 years 7 months ago #218620
by Mon2016
Last two exclusive rows numerical matrix was created by Mon2016
Hi all,
I am asking a question of type matrix of numbers and using the checkboxes.
I tell you that I need to exclude the last two options from each column
That is, if SQ005_A and SQ006_A
are checked, exclude all others SQ001_A SQ002_A SQ003_A SQ004_A
The same happens with column B, C, D
I found something very useful in the forum, but it only works to make the last row exclusive, and I'm looking to make the last two exclusive.
I appreciate your help too much
I am asking a question of type matrix of numbers and using the checkboxes.
I tell you that I need to exclude the last two options from each column
That is, if SQ005_A and SQ006_A
are checked, exclude all others SQ001_A SQ002_A SQ003_A SQ004_A
The same happens with column B, C, D
I found something very useful in the forum, but it only works to make the last row exclusive, and I'm looking to make the last two exclusive.
I appreciate your help too much
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10635
- Thank you received: 3699
2 years 7 months ago #218633
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Last two exclusive rows numerical matrix
Err...what did you find?
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- Mon2016
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 77
- Thank you received: 0
2 years 7 months ago #218639
by Mon2016
Replied by Mon2016 on topic Last two exclusive rows numerical matrix
Hi @tpartner
Thanks for answering,
I found this script:
<script type="text/javascript" charset="utf-8">
$(document).on('ready pjax:scriptcomplete',function(){
// Identify this question
var qID = '{QID}';
var thisQuestion = $('#question'+qID);
// Assign column-specific attributes and classnames
$('tr.subquestion-list', thisQuestion).each(function(i) {
$('> *', this).each(function(i) {
$(this).attr('data-column', i);
});
});
$('tr.subquestion-list:last td.answer-item', thisQuestion).addClass('exclusive-item');
// A function to un-check boxes
function resetCheckbox(thisItem) {
$(':hidden', thisItem).val('');
$(':checkbox', thisItem).prop('checked', false).trigger('change');
}
// Listener on the checkboxes
$(':checkbox', thisQuestion).on('change', function(e) {
if($(this).is(':checked')) {
var thisItem = $(this).closest('.answer-item');
var thisColumn = $(thisItem).attr('data-column');
var items = $('td.answer-item[data-column="'+thisColumn+'"].exclusive-item', thisQuestion);
if($(thisItem).hasClass('exclusive-item')) {
items = $('td.answer-item[data-column="'+thisColumn+'"]:not(.exclusive-item)', thisQuestion);
}
$.each(items, function(i, el) {
resetCheckbox(el);
});
}
});
});
</script>
In this post:
forums.limesurvey.org/forum/can-i-do-thi...es-all-others#208856
As I mentioned before, it works very well excluding the last row of options, but I wish it was like this for the last two.
Thanks again.
Thanks for answering,
I found this script:
<script type="text/javascript" charset="utf-8">
$(document).on('ready pjax:scriptcomplete',function(){
// Identify this question
var qID = '{QID}';
var thisQuestion = $('#question'+qID);
// Assign column-specific attributes and classnames
$('tr.subquestion-list', thisQuestion).each(function(i) {
$('> *', this).each(function(i) {
$(this).attr('data-column', i);
});
});
$('tr.subquestion-list:last td.answer-item', thisQuestion).addClass('exclusive-item');
// A function to un-check boxes
function resetCheckbox(thisItem) {
$(':hidden', thisItem).val('');
$(':checkbox', thisItem).prop('checked', false).trigger('change');
}
// Listener on the checkboxes
$(':checkbox', thisQuestion).on('change', function(e) {
if($(this).is(':checked')) {
var thisItem = $(this).closest('.answer-item');
var thisColumn = $(thisItem).attr('data-column');
var items = $('td.answer-item[data-column="'+thisColumn+'"].exclusive-item', thisQuestion);
if($(thisItem).hasClass('exclusive-item')) {
items = $('td.answer-item[data-column="'+thisColumn+'"]:not(.exclusive-item)', thisQuestion);
}
$.each(items, function(i, el) {
resetCheckbox(el);
});
}
});
});
</script>
In this post:
forums.limesurvey.org/forum/can-i-do-thi...es-all-others#208856
As I mentioned before, it works very well excluding the last row of options, but I wish it was like this for the last two.
Thanks again.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10635
- Thank you received: 3699
2 years 7 months ago #218649
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Last two exclusive rows numerical matrix
What LimeSurvey version do you use?
Can you attach a small sample survey (.lss file) containing only that question and your JavaScript?
Can you attach a small sample survey (.lss file) containing only that question and your JavaScript?
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- Mon2016
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 77
- Thank you received: 0
2 years 7 months ago #218656
by Mon2016
Replied by Mon2016 on topic Last two exclusive rows numerical matrix
Thanks Tony,
I am attaching the lss survey with the question and the script.
I tell you that I am using 3.25 and 2.50. I ran it in both versions and with the script it works for both versions.
I am attaching the lss survey with the question and the script.
I tell you that I am using 3.25 and 2.50. I ran it in both versions and with the script it works for both versions.
Attachments:
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10635
- Thank you received: 3699
2 years 7 months ago #218665
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Last two exclusive rows numerical matrix
This script will render the last two rows of an array-numbers-checkboxes question as exclusive.
Sample survey attached:
Code:
<script type="text/javascript" data-author="Tony Partner"> $(document).on('ready pjax:scriptcomplete',function(){ // Identify this question var qID = '{QID}'; var thisQuestion = $('#question'+qID); // Assign column-specific attributes and classnames $('tr.subquestion-list', thisQuestion).each(function(i) { $('> *', this).each(function(i) { $(this).attr('data-column', i); }); }); $('tr.subquestion-list', thisQuestion).slice(-2).find('td.answer-item').addClass('exclusive-item'); // A function to un-check boxes function resetCheckbox(thisItem) { $(':hidden', thisItem).val(''); $(':checkbox', thisItem).prop('checked', false).trigger('change'); } // Listener on the checkboxes $(':checkbox', thisQuestion).on('change', function(e) { if($(this).is(':checked')) { var thisItem = $(this).closest('.answer-item'); var thisColumn = $(thisItem).attr('data-column'); var items = $('td.answer-item[data-column="'+thisColumn+'"].exclusive-item', thisQuestion); if($(thisItem).hasClass('exclusive-item')) { items = $('td.answer-item[data-column="'+thisColumn+'"]', thisQuestion).not(thisItem); } $.each(items, function(i, el) { resetCheckbox(el); }); } }); }); </script>
Sample survey attached:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.