- Posts: 136
- Thank you received: 4
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
@tpartner, I need you help!!!the maximum answers per row
- surveySn
- Topic Author
- Offline
- Premium Member
Less
More
5 years 2 months ago #180012
by surveySn
The above is the restricted column.
What about Row?
www.limesurvey.org/community/forums/can-...election-imit#180008
This way, HTTP 500
@tpartner, I need you help!!!the maximum answers per row was created by surveySn
Code:
<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>
The above is the restricted column.
What about Row?
www.limesurvey.org/community/forums/can-...election-imit#180008
This way, HTTP 500
The topic has been locked.
- surveySn
- Topic Author
- Offline
- Premium Member
Less
More
- Posts: 136
- Thank you received: 4
5 years 2 months ago #180413
by surveySn
Replied by surveySn on topic @tpartner, I need you help!!!the maximum answers per row
Has anybody helped me?
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10099
- Thank you received: 3589
5 years 2 months ago - 5 years 2 months ago #180430
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 @tpartner, I need you help!!!the maximum answers per row
Placing this script in the source of an array-numbers-checkboxes question will enforce a maximum of 3 items checked per row.
Sample survey attached:
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Define the maximum answers per row var maxAnswers = 3; // Identify this question var thisQuestion = $('#question{QID}'); // Listener on the checkboxes $('input[type="checkbox"]', thisQuestion).on('change', function(e) { var thisRow = $(this).closest('tr'); $('input[type="checkbox"]', thisRow).prop('disabled', false); // If max reached, disable unchecked inputs in this row if($('input[type="checkbox"]:checked', thisRow).length >= maxAnswers) { $('input[type="checkbox"]:not(:checked)', thisRow).prop('disabled', true); } }); }); </script>
Sample survey attached:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 5 years 2 months ago by tpartner.
The following user(s) said Thank You: surveySn
The topic has been locked.
- surveySn
- Topic Author
- Offline
- Premium Member
Less
More
- Posts: 136
- Thank you received: 4
5 years 2 months ago #180431
by surveySn
Replied by surveySn on topic @tpartner, I need you help!!!the maximum answers per row
Thank you very much, tpartner.
The topic has been locked.
- dirk01
- Offline
- New Member
Less
More
- Posts: 19
- Thank you received: 4
4 years 10 months ago #185192
by dirk01
Replied by dirk01 on topic @tpartner, I need you help!!!the maximum answers per row
Hi there,
Is it possible to change the script to an array text question.
If someone fills in one or two options in a one row, the other options are disabled.
For instance, how many pieces of fruit do you eat, and they can answer by day, week, month or year?
Kind regards,
Dirk
Is it possible to change the script to an array text question.
If someone fills in one or two options in a one row, the other options are disabled.
For instance, how many pieces of fruit do you eat, and they can answer by day, week, month or year?
Kind regards,
Dirk
Attachments:
The topic has been locked.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12881
- Thank you received: 3965
4 years 10 months ago #185199
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic @tpartner, I need you help!!!the maximum answers per row
That you can do easily by the built-in option of question validation
(count(self.sq_SQ001_X)<4) and (count(self.sq_SQ002_X)<4) and (count(self.sq_SQ003_X)<4) and (count(self.sq_SQ004_X)<4)
Joffm
(count(self.sq_SQ001_X)<4) and (count(self.sq_SQ002_X)<4) and (count(self.sq_SQ003_X)<4) and (count(self.sq_SQ004_X)<4)
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
- dirk01
- Offline
- New Member
Less
More
- Posts: 19
- Thank you received: 4
4 years 10 months ago #185200
by dirk01
Replied by dirk01 on topic @tpartner, I need you help!!!the maximum answers per row
Ok, thanks for the quick respons.
I understand it and I've used the EM before, but in this case it is rather complicated because the options should be disabled on a row per row basis.
So in the example only cell "option1--X005" should be disabled, not the other rows/cells of the array.
I understand it and I've used the EM before, but in this case it is rather complicated because the options should be disabled on a row per row basis.
So in the example only cell "option1--X005" should be disabled, not the other rows/cells of the array.
The topic has been locked.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12881
- Thank you received: 3965
4 years 10 months ago #185208
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic @tpartner, I need you help!!!the maximum answers per row
Yes, I know.
As you see in the validation there is the check row by row.
Only if there are more than 3 mentions in one row the error message will appear.
But I admit that it is a bit confusing that the whole question is marked as "wrong" in case there are 4 mentions in one row.
On the other side you get the message immediately after your wrong entry.
Joffm
You see, I prefer built-in features. Too many times a workaround didn't work anymore after an update or a new major release and had to be adapted.
As you see in the validation there is the check row by row.
Only if there are more than 3 mentions in one row the error message will appear.
But I admit that it is a bit confusing that the whole question is marked as "wrong" in case there are 4 mentions in one row.
On the other side you get the message immediately after your wrong entry.
Joffm
You see, I prefer built-in features. Too many times a workaround didn't work anymore after an update or a new major release and had to be adapted.
Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: DenisChenu
The topic has been locked.
- dirk01
- Offline
- New Member
Less
More
- Posts: 19
- Thank you received: 4
4 years 10 months ago #185247
by dirk01
Replied by dirk01 on topic @tpartner, I need you help!!!the maximum answers per row
Thanks a lot. I should have given the expression a closer look.
I use it sometimes for calculations, not for validations.
Dirk
I use it sometimes for calculations, not for validations.
Dirk
The topic has been locked.