Welcome to the LimeSurvey Community Forum

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

Array - Max answers per column

  • boshra.m
  • boshra.m's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
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.
 

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 7 months ago #232186 by Joffm
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)




 

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • boshra.m
  • boshra.m's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
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.
Last edit: 1 year 7 months ago by boshra.m.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 7 months ago - 1 year 7 months ago #232233 by Joffm
Replied by Joffm on topic Array - Max answers per column
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.
[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
  • boshra.m's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
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!

Please Log in to join the conversation.

  • boshra.m
  • boshra.m's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
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

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 6 months ago #232375 by tpartner
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
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 6 months ago - 1 year 6 months ago #232377 by Joffm
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?

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
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
  • boshra.m's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
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.

Lime-years ahead

Online-surveys for every purse and purpose