- Posts: 2
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Array filter with array with numbers
- depinstitut
- Topic Author
- Offline
- New Member
Less
More
1 year 8 months ago #230964
by depinstitut
Array filter with array with numbers was created by depinstitut
Please help us help you and fill where relevant:
Your LimeSurvey version: Version 5.3.25
Own server or LimeSurvey hosting: LimeSurvey hosting
Survey theme/template: Extension of fruity.
==================
We are trying to do an Array -Numbers with Checkbox display, that has answer response filters from a previous question for the rows and that doesn't allow for more than 3 responses per row and also excludes other responses on the row if the respondent answers N/NC.
For now in the equation of the subquestion we have established that you can't continue if you mark more than 3 responses but if you select all the options on the previous question that is the filter array - it stops working.
The survey/questions can be seen here: [url] depinstitut.limequery.org/416864?lang=ca [/url] Thank you for any help/guidance in advance,
Rachel
Your LimeSurvey version: Version 5.3.25
Own server or LimeSurvey hosting: LimeSurvey hosting
Survey theme/template: Extension of fruity.
==================
We are trying to do an Array -Numbers with Checkbox display, that has answer response filters from a previous question for the rows and that doesn't allow for more than 3 responses per row and also excludes other responses on the row if the respondent answers N/NC.
For now in the equation of the subquestion we have established that you can't continue if you mark more than 3 responses but if you select all the options on the previous question that is the filter array - it stops working.
The survey/questions can be seen here: [url] depinstitut.limequery.org/416864?lang=ca [/url] Thank you for any help/guidance in advance,
Rachel
Attachments:
Please Log in to join the conversation.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10099
- Thank you received: 3589
1 year 8 months ago #230968
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 filter with array with numbers
Regarding the exclusive column, see the second script here -
forums.limesurvey.org/forum/search?query...artner&childforums=1
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12888
- Thank you received: 3965
1 year 8 months ago #230969
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Array filter with array with numbers
Hi,
1. You should use ".NAOK" in your question validation.
2. It is a question validation, not a subquestion validation.
3. I included the script Tony mentioned.
4. I can't reproduce that something stops working, even in your linked survey.
Joffm
1. You should use ".NAOK" in your question validation.
2. It is a question validation, not a subquestion validation.
3. I included the script Tony mentioned.
4. I can't reproduce that something stops working, even in your linked survey.
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Please Log in to join the conversation.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10099
- Thank you received: 3589
1 year 8 months ago #230971
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 filter with array with numbers
Here is a script that will:
1) Render the last column as exclusive
2) Limit the non-exclusive items to a max of 3 per row.
This can be used in conjunction with Joffm's validation.
Sample survey attached:
1) Render the last column as exclusive
2) Limit the non-exclusive items to a max of 3 per row.
This can be used in conjunction with Joffm's validation.
Code:
<script type="text/javascript" data-author="Tony Partner"> $(document).on('ready pjax:scriptcomplete',function(){ var thisQuestion = $('#question{QID}') // Add some classes to the checkbox cells $('td.checkbox-item', thisQuestion).addClass('normal-item'); $('tr.subquestion-list', thisQuestion).each(function(i) { $('.normal-item:last', this).removeClass('normal-item').addClass('exclusive-item') }); // A listener on the checkboxes $('input[type="checkbox"]', thisQuestion).on('change', function (event) { handleCheckboxes($(this)); }); function handleCheckboxes(thisInput) { var thisCell = $(thisInput).closest('td'); var thisRow = $(thisCell).closest('tr'); $('input[type="checkbox"]', thisRow).prop('disabled', false); $('td', thisRow).closest('td').removeClass('checked-item'); $('input[type="checkbox"]:checked', thisRow).closest('td').addClass('checked-item'); // Exclusive item if($('.exclusive-item input[type="checkbox"]:eq(0)', thisRow).is(':checked')) { $('.normal-item input[type="hidden"]', thisRow).val(''); $('.normal-item input[type="checkbox"]', thisRow).prop('checked', false).prop('disabled', true); } else { $('.exclusive-item input[type="hidden"]', thisRow).val(''); $('.exclusive-item input[type="checkbox"]', thisRow).prop('checked', false); } // Max 3 answers per row if($('input[type="checkbox"]:checked', thisRow).length == 3) { $('td:not(.exclusive-item):not(.checked-item)', thisRow).find('input[type="checkbox"]').prop('disabled', true); } // Check conditions (relevance) $('td.checkbox-item', thisRow).each(function(i) { var thisValue = ''; if($('input[type="checkbox"]', this).is(':checked')) { thisValue = 1; } var thisSGQA = $('input[type="checkbox"]', this).attr('id').replace(/cbox_/, ''); $('input[type="hidden"]', this).attr('value', thisValue); fixnum_checkconditions(thisValue, thisSGQA, 'hidden'); }); } }); </script>
Sample survey attached:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: Joffm
Please Log in to join the conversation.