- Posts: 102
- Thank you received: 2
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Array - Max answers per column
- boshra.m
- Topic Author
- Offline
- Premium Member
Less
More
1 year 7 months ago #232185
by boshra.m
Array - Max answers per column was created by boshra.m
Please help us help you and fill where relevant:
Your LimeSurvey version: LimeSurvey Cloud Version 5.3.31
Own server or LimeSurvey hosting: LimeSurvey hosting
Survey theme/template: Fruity
==================
Hello,
I have used this:
to allow for participants to only select 1 answer per column for an array (number) type of question but I can't figure out how to implement the same thing for just a normal array question. I also saw that I can use self question validation but also am unsure of how to implement it correctly. Any direction would be much appreciated. Thank you.<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
// Define the maximum answers per column
var maxAnswers = 1;
// Identify this question
var thisQuestion = $('#question{QID}');
// Index the array columns
$('table.subquestion-list tr', thisQuestion).each(function(i) {
$('> *', this).each(function(i) {
$(this).attr('data-index', i);
});
});
// Listener on the checkboxes
$('input[type="checkbox"]', thisQuestion).on('change', function(e) {
var thisIndex = $(this).closest('.answer-item').attr('data-index');
$('[data-index="'+thisIndex+'"] input[type="checkbox"]', thisQuestion).prop('disabled', false);
// If max reached, disable unchecked inputs in this column
if($('[data-index="'+thisIndex+'"] input[type="checkbox"]:checked', thisQuestion).length >= maxAnswers) {
$('[data-index="'+thisIndex+'"] input[type="checkbox"]:not(:checked)', thisQuestion).prop('disabled', true);
}
});
});
</script>
to allow for participants to only select 1 answer per column for an array (number) type of question but I can't figure out how to implement the same thing for just a normal array question. I also saw that I can use self question validation but also am unsure of how to implement it correctly. Any direction would be much appreciated.
Thank you.
Your LimeSurvey version: LimeSurvey Cloud Version 5.3.31
Own server or LimeSurvey hosting: LimeSurvey hosting
Survey theme/template: Fruity
==================
Hello,
I have used this:
to allow for participants to only select 1 answer per column for an array (number) type of question but I can't figure out how to implement the same thing for just a normal array question. I also saw that I can use self question validation but also am unsure of how to implement it correctly. Any direction would be much appreciated. Thank you.<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
// Define the maximum answers per column
var maxAnswers = 1;
// Identify this question
var thisQuestion = $('#question{QID}');
// Index the array columns
$('table.subquestion-list tr', thisQuestion).each(function(i) {
$('> *', this).each(function(i) {
$(this).attr('data-index', i);
});
});
// Listener on the checkboxes
$('input[type="checkbox"]', thisQuestion).on('change', function(e) {
var thisIndex = $(this).closest('.answer-item').attr('data-index');
$('[data-index="'+thisIndex+'"] input[type="checkbox"]', thisQuestion).prop('disabled', false);
// If max reached, disable unchecked inputs in this column
if($('[data-index="'+thisIndex+'"] input[type="checkbox"]:checked', thisQuestion).length >= maxAnswers) {
$('[data-index="'+thisIndex+'"] input[type="checkbox"]:not(:checked)', thisQuestion).prop('disabled', true);
}
});
});
</script>
to allow for participants to only select 1 answer per column for an array (number) type of question but I can't figure out how to implement the same thing for just a normal array question. I also saw that I can use self question validation but also am unsure of how to implement it correctly. Any direction would be much appreciated.
Thank you.
Please Log in to join the conversation.
- Joffm
- Away
- LimeSurvey Community Team
Less
More
- Posts: 12933
- Thank you received: 3979
1 year 7 months ago #232186
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Array - Max answers per column
Hi,
to achieve it in a normal array use the function "unique(x)"
So in the "question valdation equation" enter unique(self)
to achieve it in a normal array use the function "unique(x)"
So in the "question valdation equation" enter unique(self)
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Please Log in to join the conversation.
- boshra.m
- Topic Author
- Offline
- Premium Member
Less
More
- Posts: 102
- Thank you received: 2
1 year 7 months ago - 1 year 7 months ago #232232
by boshra.m
Replied by boshra.m on topic Array - Max answers per column
Hello,
Thanks for your response.
So I entered "unique(self.sq_1c) and unique(self.sq_2c) and unique(self.sq_3c) and unique(self.sq_4c)" into the question validator (with 1c,2c,3c,4c being the column answer identifiers). However, this did not work, am I missing something?
Thank you.
Thanks for your response.
So I entered "unique(self.sq_1c) and unique(self.sq_2c) and unique(self.sq_3c) and unique(self.sq_4c)" into the question validator (with 1c,2c,3c,4c being the column answer identifiers). However, this did not work, am I missing something?
Thank you.
Last edit: 1 year 7 months ago by boshra.m.
Please Log in to join the conversation.
- Joffm
- Away
- LimeSurvey Community Team
Less
More
- Posts: 12933
- Thank you received: 3979
1 year 7 months ago - 1 year 7 months ago #232233
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Array - Max answers per column
Hi,
where did you read anything about unique(self.sq_2c)?
I see only
In an array "unique(self.sq_2c)" is useless, because it is unique by definition.
The code of one column has one and always the same value.
Here you may see some alternatives to force unique values.
[url] demo.sondages.pro/714997?lang=en# [/url]
where did you read anything about unique(self.sq_2c)?
I see only
JoffmSo in the "question valdation equation" enter unique(self)
In an array "unique(self.sq_2c)" is useless, because it is unique by definition.
The code of one column has one and always the same value.
Here you may see some alternatives to force unique values.
[url] demo.sondages.pro/714997?lang=en# [/url]
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 year 7 months ago by Joffm.
The following user(s) said Thank You: boshra.m
Please Log in to join the conversation.
- boshra.m
- Topic Author
- Offline
- Premium Member
Less
More
- Posts: 102
- Thank you received: 2
1 year 7 months ago #232234
by boshra.m
Replied by boshra.m on topic Array - Max answers per column
Hello,
Just tying in what I saw on other threads. I see now I was overcomplicating things.
Thank you!
Just tying in what I saw on other threads. I see now I was overcomplicating things.
Thank you!
Please Log in to join the conversation.
- boshra.m
- Topic Author
- Offline
- Premium Member
Less
More
- Posts: 102
- Thank you received: 2
1 year 6 months ago #232365
by boshra.m
Replied by boshra.m on topic Array - Max answers per column
Hello,
Now I am wondering if it is possible to have 1) 1 answer per column (which I have used with "unique(self)" AND allow for 2) Multiple answers per row in a regular array question? Or even the checkbox array.
Thank you,
Boshra
Now I am wondering if it is possible to have 1) 1 answer per column (which I have used with "unique(self)" AND allow for 2) Multiple answers per row in a regular array question? Or even the checkbox array.
Thank you,
Boshra
Please Log in to join the conversation.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
1 year 6 months ago #232375
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 Array - Max answers per column
You cannot have multiple answer per row in a normal array question because it uses radio inputs which, by definition, only allow one selected.
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.
- Joffm
- Away
- LimeSurvey Community Team
Less
More
- Posts: 12933
- Thank you received: 3979
1 year 6 months ago - 1 year 6 months ago #232377
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Array - Max answers per column
Sorry, now I am confused.
What exactly are you going to achieve?
Can't you show an example?
So, please, explain, what you want to ask, show something like a drawing how it should look like
Joffm
What exactly are you going to achieve?
Can't you show an example?
Not in an array. But it is the exact requirement for an "array by columns"1) 1 answer per column AND allow for
2) Multiple answers per row in a regular array question?
This is a further option to achieve it. Here you have to add some validationOr even the checkbox array
So, please, explain, what you want to ask, show something like a drawing how it should look like
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 year 6 months ago by Joffm.
The following user(s) said Thank You: boshra.m
Please Log in to join the conversation.
- boshra.m
- Topic Author
- Offline
- Premium Member
Less
More
- Posts: 102
- Thank you received: 2
1 year 6 months ago #232397
by boshra.m
Replied by boshra.m on topic Array - Max answers per column
The array by columns is exactly what I needed. Thank you very much.
Please Log in to join the conversation.