- Posts: 3
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Dual Scale - Allow to either answer on both scales or neither
- tillB
- Topic Author
- Offline
- New Member
Less
More
8 years 6 months ago #124273
by tillB
Dual Scale - Allow to either answer on both scales or neither was created by tillB
Hey Limes,
i have a survey with a lot of Dual Scale questions. I would like to know, if it is possible that participants can either give an answer on both scales or on none. To clarifiy: i dont want to make the question required, only if they answer any question on one of the two scales, they also would have to give an answer on the other scale.
If there is no Limesurvey feature for that and a js solution is necessary, i have another question . Since i have a lot of questions, i would like to know, if there is a way to get a list of all questionIDs of all dual scale questions, so i dont have to go through every question and copy the id out myself in order to apply javascript to all of them.
Thanks a lot for your help in advance, i really appreciate it!
i have a survey with a lot of Dual Scale questions. I would like to know, if it is possible that participants can either give an answer on both scales or on none. To clarifiy: i dont want to make the question required, only if they answer any question on one of the two scales, they also would have to give an answer on the other scale.
If there is no Limesurvey feature for that and a js solution is necessary, i have another question . Since i have a lot of questions, i would like to know, if there is a way to get a list of all questionIDs of all dual scale questions, so i dont have to go through every question and copy the id out myself in order to apply javascript to all of them.
Thanks a lot for your help in advance, i really appreciate it!
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10611
- Thank you received: 3690
8 years 6 months ago - 8 years 6 months ago #124337
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 Dual Scale - Allow to either answer on both scales or neither
You can achieve this behaviour with JavaScript:
1) Place this small plugin at the end of template.js. The plugin interrupts the next/submit process and checks for rows with single answers. If found, a class is applied to that row, an alert is popped up and the next/submit process is aborted.
2) Place something like this at the end of template.css to highlight the invalid rows.
3) Place this in the source of every question you want to apply the plugin to:
Regarding your question about finding all of the array-dual-scale questions - you can search the Survey Logic File for all instances of "Array dual scale".
1) Place this small plugin at the end of template.js. The plugin interrupts the next/submit process and checks for rows with single answers. If found, a class is applied to that row, an alert is popped up and the next/submit process is aborted.
Code:
// A jQuery plugin ensure that there are no rows with single answers (function( $ ){ $.fn.lsHandleArray = function(options) { var opts = $.extend( { alertText: 'Please complete the indicated rows.' }, options); return this.each(function() { var thisQuestion = $(this); // Interrupt the Next/Submit click $('#movenextbtn, #movesubmitbtn').bind('click', function () { // Reset $('tr.answers-list', thisQuestion).removeClass('invalid-answer'); // Loop through the array rows $('tr.answers-list', thisQuestion).each(function(i) { if($('input.radio:checked', this).length == 1) { $(this).addClass('invalid-answer'); } }); // Pop up alert and abort submit if invalid rows found if($('tr.invalid-answer', thisQuestion).length > 0) { alert(opts.alertText); $('#movenextbtn, #movesubmitbtn').blur(); return false; } }); }); }; })( jQuery );
2) Place something like this at the end of template.css to highlight the invalid rows.
Code:
tr.invalid-answer { background: pink; }
3) Place this in the source of every question you want to apply the plugin to:
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { $('#question{QID}').lsHandleArray({alertText: 'Please complete the indicated rows.'}); }); </script>
Regarding your question about finding all of the array-dual-scale questions - you can search the Survey Logic File for all instances of "Array dual scale".
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 8 years 6 months ago by tpartner.
The topic has been locked.
- tillB
- Topic Author
- Offline
- New Member
Less
More
- Posts: 3
- Thank you received: 0
8 years 6 months ago #124354
by tillB
Replied by tillB on topic Dual Scale - Allow to either answer on both scales or neither
Thanks a lot for that solution, tpartner!
The topic has been locked.