Array - Max answers per column

More
1 week 4 days ago #232185 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.
 

Please Log in to join the conversation.

More
1 week 4 days ago #232186 by Joffm
Hi,
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
Attachments:

Please Log in to join the conversation.

More
1 week 3 days ago - 1 week 3 days ago #232232 by boshra.m
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.
Last edit: 1 week 3 days ago by boshra.m.

Please Log in to join the conversation.

More
1 week 3 days ago - 1 week 3 days ago #232233 by Joffm
Hi,
where did you read anything about unique(self.sq_2c)?
I see only

So in the "question valdation equation" enter unique(self)

Joffm

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.
demo.sondages.pro/714997?lang=en#
 


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 week 3 days ago by Joffm.
The following user(s) said Thank You: boshra.m

Please Log in to join the conversation.

More
1 week 3 days ago #232234 by boshra.m
Hello,

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.

More
6 days 8 hours ago #232365 by boshra.m
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

Please Log in to join the conversation.

More
6 days 2 hours ago #232375 by tpartner
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.

More
6 days 1 hour ago - 6 days 1 hour ago #232377 by Joffm
Sorry, now I am confused.
What exactly are you going to achieve?
Can't you show an example?

1) 1 answer per column  AND allow for
2) Multiple answers per row in a regular array question? 

Not in an array. But it is the exact requirement for an "array by columns"
 
  

Or even the checkbox array

This is a further option to achieve it. Here you have to add some validation 

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
Attachments:
Last edit: 6 days 1 hour ago by Joffm.
The following user(s) said Thank You: boshra.m

Please Log in to join the conversation.

More
5 days 8 hours ago #232397 by boshra.m
The array by columns is exactly what I needed. Thank you very much.

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now