- Posts: 26
- Thank you received: 1
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Array prefilled based on previous array
- Matiasko
- Topic Author
- Offline
- Junior Member
Less
More
6 years 1 month ago - 6 years 1 month ago #164625
by Matiasko
Array prefilled based on previous array was created by Matiasko
Hello,
in my survey, I would like to ask 3 array questions in a group as attached.
With it I need three such behaviors:
I would like to highlight that I am using the newest beta version of LimeSurvey.
Best regards
Mateusz
in my survey, I would like to ask 3 array questions in a group as attached.
With it I need three such behaviors:
- prefill all answers in the first table with first option 'Did not know'
- if in the first or second table something else than 'Did not know' was selected, 'Did/do not know' should be disabled in the following tables. For example, if for Lang1 B2 was selected in the first array than 'Did not know' in the second and 'Do not know' in the third table should be disabled
- if e.x. option B2 was selected in the first table it should be prefilled in the second table in corresponding row, if option C1 was selected in the second table it should be prefilled in the third table in the corresponding row
I would like to highlight that I am using the newest beta version of LimeSurvey.
Best regards
Mateusz
Attachments:
Last edit: 6 years 1 month ago by Matiasko.
The topic has been locked.
- holch
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 11645
- Thank you received: 2739
6 years 1 month ago #164628
by holch
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Replied by holch on topic Array prefilled based on previous array
What is the "newest beta" of Limesurvey? If you are really running a beta version, than you should update to the latest stable version.
Please post the exact version of Limesurvey, you can find it at the bottom right of your admin screen. Just copy and paste it.
Please post the exact version of Limesurvey, you can find it at the bottom right of your admin screen. Just copy and paste it.
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
The topic has been locked.
- Matiasko
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 26
- Thank you received: 1
6 years 1 month ago #164630
by Matiasko
Replied by Matiasko on topic Array prefilled based on previous array
Version: 3.3.1
Kompilation: 180214
Kompilation: 180214
The topic has been locked.
- holch
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 11645
- Thank you received: 2739
6 years 1 month ago #164637
by holch
Ideally you would provide a .lss file, because with a .lsg file the helpers here must either import your question group into an existing survey (which most wouldn't like to do) or they have to create a new survey to import this .lsg to. In both cases, this means additonal work for the helpers.
I will see if I find the time for looking into this later today.
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Replied by holch on topic Array prefilled based on previous array
That is not a beta and certainly also not the newest (3.4.2).Version: 3.3.1
Kompilation: 180214
Ideally you would provide a .lss file, because with a .lsg file the helpers here must either import your question group into an existing survey (which most wouldn't like to do) or they have to create a new survey to import this .lsg to. In both cases, this means additonal work for the helpers.
I will see if I find the time for looking into this later today.
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
The topic has been locked.
- Matiasko
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 26
- Thank you received: 1
6 years 1 month ago #164645
by Matiasko
Replied by Matiasko on topic Array prefilled based on previous array
Here is lss file
Attachments:
The topic has been locked.
- tpartner
- Away
- LimeSurvey Community Team
Less
More
- Posts: 10104
- Thank you received: 3593
6 years 1 month ago - 6 years 1 month ago #164651
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 prefilled based on previous array
In my opinion you logic will is flawed because you can still enter a lower language level now than when you started.
Having said that, placing this script in the source of the first question will meet your requirements.
Sample survey attached:
Having said that, placing this script in the source of the first question will meet your requirements.
Code:
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ // Identify the questions var q1ID = {QID}; var q1 = $('#question'+q1ID); var q2ID = $(q1).nextAll('.array-flexible-row:eq(0)').attr('id').replace(/question/, ''); var q2 = $('#question'+q2ID); var q3ID = $(q1).nextAll('.array-flexible-row:eq(1)').attr('id').replace(/question/, ''); var q3 = $('#question'+q3ID); var arrays = $(q1).add(q2).add(q3); // Assign column-specific classes $('table.subquestion-list tr', arrays).each(function(i) { $('> *:gt(0)', this).each(function(i){ $(this).addClass('column-'+(i+1)); }); }); // Default answers in Q1 $('table.subquestion-list tr.answers-list', q1).each(function(i) { if($('input[type="radio"]:checked', this).length == 0) { $('input[type="radio"]:first', this).trigger('click'); } }); // Listener on the Q1 radios $('input[type="radio"]', q1).on('click', function(i) { handleRadios(this); }); $('input[type="radio"]', q2).on('click', function(i) { handleRadios(this); }); function handleRadios(el) { var thisQID = $(el).closest('.array-flexible-row').attr('id').replace(/question/, ''); var nextQID = $(el).closest('.array-flexible-row').nextAll('.array-flexible-row:eq(0)').attr('id').replace(/question/, ''); var thisSQCode = $(el).attr('name').split('X'+thisQID)[1]; var thisQCode = $(el).val(); var nextCol1Radio = $('tr[id$="X'+nextQID+thisSQCode+'"] .column-1 input[type="radio"]'); var nextThisRadio = $('tr[id$="X'+nextQID+thisSQCode+'"] input[type="radio"][value="'+thisQCode+'"]'); if(!$(el).closest('td').hasClass('column-1')) { // Disable column-1 in the next question $(nextCol1Radio).prop('checked', false).prop('disabled', true); // Trigger the corresponding radio in the next question $(nextThisRadio).trigger('click'); } else { // Enable column-1 in the next question $(nextCol1Radio).prop('disabled', false); } } }); </script>
Sample survey attached:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
Last edit: 6 years 1 month ago by tpartner.
The following user(s) said Thank You: Matiasko
The topic has been locked.
- Matiasko
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 26
- Thank you received: 1
6 years 1 month ago #164708
by Matiasko
Replied by Matiasko on topic Array prefilled based on previous array
Works like a charm! Splendid code
As for the logic, I am fully aware of this, however, thank you for pointing it out.
I truly appreciate your help!
As for the logic, I am fully aware of this, however, thank you for pointing it out.
I truly appreciate your help!
The topic has been locked.