Welcome to the LimeSurvey Community Forum

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

Dual scale array with dropdown lists--reject partial responses?

  • sD960
  • sD960's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
10 years 2 months ago #104142 by sD960
I am using the question type described in the manual as "Array (flexible labels) dual scale (dropdown list layout)". Here's a (fake) example: I want to know about people's music listening preferences, so I ask: For each composer whose music you listen to, indicate primary type of music you listen to, and then rate it. My sub-questions are composers; Beethoven, Schubert, Bartok. My first set of dropdown lists are types of compositions; sonatas, songs, symphonies. My second set of dropdown lists are ratings; love, indifferent, hate. I've used the advanced settings to require a minimum of 1 response, as I only want survey-takers to respond for composers they listen to, and not necessarily for all of them.

If a survey-taker responds, say, Beethoven--sonata--love and makes no other responses, that's fine, and Limesurvey accepts that. That's good. If the survey-taker responds, say, Beethoven--sonata and leaves out the rating, Limesurvey, quite appropriately, prompts the survey-taker to complete the answer. That's good. The problem is, if the survey-taker responds Beethoven--sonata--love AND Schubert--song with no rating, Limesurvey accepts that--that is, as long as there is at least one complete response, Limesurvey doesn't seem to care if there are also partial responses. It's important that I do not allow partial responses, partly because I have a complex set of conditionals following the array, and partly because of the nature of the information I am trying to collect in my survey.

Is there any way to set things up so that, in this type of question, Limesurvey will only accept some number of complete responses with no partial ones?

(I thought of making subsequent questions conditional on every possible legitimate answer, but 1) this is incredibly clumsy and 2) I think that would cause the survey to skip the subsequent questions if there are partial answers.)

Thanks!
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 2 months ago #104174 by tpartner
There is no built-in method to validate that question type in that way but you can use JavaScript to accomplish it.

I am assuming you are using LimeSurvey 2.05...

1) Set up your survey to use JavaScript

2) Add the following script to the question source of the array:
Code:
<script type="text/javascript" charset="utf-8">  
 
  $(document).ready(function() {
 
    // The alert message (edit as necessary)
    var msg = 'Each answered row must have values for BOTH dropdowns.';
 
    // Identify this question
    var thisQuestion = $('#question{self.qid}');
 
    // Wrap the answer text in <span> elements
    $('th.answertext').wrapInner('<span class="answertext-inner" />');
 
    // Interrupt the Next/Submit function
    $('form#limesurvey').submit(function(){
 
      // Override the built-in "disable navigation buttons" feature
      $('#moveprevbtn, #movenextbtn, #movesubmitbtn').prop('disabled', false);
 
      // Validate each row
      $('.answertext-inner', this).removeClass('errormandatory');
      $('tr.dropdown-list', thisQuestion).each(function(i) {
        if($('option[value=""]:selected', this).length == 1) {
          $('.answertext-inner', this).addClass('errormandatory');
        }
      });
 
      // If an invalid row is found, pop up the alert and abort the submit
      if($('.answertext-inner.errormandatory', thisQuestion).length != 0) {
        alert(msg);
        return false;
      }
    });
  });
 
</script>


.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • sD960
  • sD960's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
10 years 2 months ago #104188 by sD960
Thanks. I'm not a programmer, but will pass your suggestion along to the higher powers and will let you know if it works.

Do you think it's worth suggesting to Limesurvey's developers that this be incorporated into the settings for drop-down arrays? That is, does this strike you as useful to anyone other than myself?
The topic has been locked.
  • sD960
  • sD960's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
10 years 2 months ago #104191 by sD960
Another question about the dual scale array with dropdown lists, though this time it looks like a bug:

Lime includes "Please choose" in each dropdown list. A survey-taker who changes his mind after making a choice can revert to "Please choose"--to continue with my previous example, a survey-taker who meant to respond to Bartok and mistakenly responded to Beethoven can undo his responses. However, if the survey-taker proceeds to the next question (via the Next button) and then returns the the dual scale array (via the Previous button), "Please choose" only reappears in the second column of dropdown lists (the "ratings" in my example) and NOT in the first column of lists ("music types"). Thus, a survey-taker can not go back and correct erroneous responses once he navigates away from the question. As the dual scale array I am using has some 15 sub-questions (with subsequent conditionals), mistakes are easy to make!
Any way around this?

I'm using Verfsion 2.05+ Build 131209.

Thanks again!
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 2 months ago #104192 by tpartner
This is not a bug. All of the drop-downs in LS only display "Please choose" if they are unanswered.

You can add your own "N/A" or "No Answer" options.

Of course, if you do so, the script above will need editing because it looks for a single unanswered drop-down in the rows.

.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • sD960
  • sD960's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
10 years 2 months ago #104195 by sD960
Yes, I thought of putting in a N/A-type option, and have anticipated the complications this could add to the data. What puzzles me, though, and the reason I suspected a bug, is that only the first column of drop-down lists no longer gives the option of reverting to "Please choose" when the survey-taker navigates away from the page and then returns to it, while the second column maintains the "Please choose" option.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 2 months ago #104199 by tpartner
Oh, yeah, I never noticed that and it does seem to be a bug.

You can use JavaScript to insert that empty option if LimeSurvey removes it. This would allow your respondents to "deselect" their answers.

Add this script to the source of the question:

Code:
<script type="text/javascript" charset="utf-8">  
 
  $(document).ready(function() {
 
    // Identify this question
    var thisQuestion = $('#question{self.qid}');
 
    // Insert an empty option
    $('.dropdown-item select', thisQuestion).each(function(i) {
      if($('option[value=""]', this).length == 0) {
        $(this).prepend('<option value="">Please choose...</option>');
      }
    });
  });
 
</script>

.

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: DenisChenu
The topic has been locked.
  • sD960
  • sD960's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
10 years 2 months ago #104217 by sD960
Thanks! I'll pass this along to the folks I'm making the survey for (and who donate to LimeSurvey) so they, in turn, can pass it along to their students who know JavaScript.

It looks like I should file a bug report!
The topic has been locked.
  • sD960
  • sD960's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
10 years 1 month ago #104277 by sD960
COMPLETE SUCCESS!! Tony, thanks so much! As I'd wanted, the array with dual dropdown lists now only accepts sub-questions when responses are chosen in both dropdown lists, and survey-takers can navigate back from subsequent questions and change their dropdown list responses back to PLEASE CHOOSE. As a very big array and lots of subsequent conditional-dependent questions is the crux of our survey, this is just what we needed.

Since we didn't even need to consult someone knowledgeable in JavaScript to incorporate the scripts you provided (I hadn't realized that they could simply be plugged into the question editing box), I'll describe the process we went through, for the benefit of forum members whose level of programming naivety matches my own:
First we googled "limesurvey javascript" to learn how to incorporate the scripts, and found manual.limesurvey.org/Workarounds:_Manip...28eg._JavaScript_etc
Scrolling down to "How to use Script (eg.JavaScript etc.) in LimeSurvey?", we followed the instructions to go to Global setting --> Security and set "Filter HTML for XSS" to "Off"--though the actual choices were, in fact, "yes" or "no", not "off" or "on". So we set it to "no". Then we went to the editing box for the array question, clicked on the "Source" button (the icon looks like a sheet of paper with lines of text), copied and pasted both of Tony's suggested scripts into the box, saved, and tested the survey. That's it.

Now I have a few questions:

1. Out of curiosity, after successfully testing the survey with the inserted scripts, we re-set the Filter HTML for XSS to "on", thinking the scripts might then no longer work. We were wrong--it seemed to make no difference either way. Can you tell me anything about the function of this filter? And what's with the on/off versus yes/no?

2. What's the best way to help out other LimeSurvey users, other than my simple description in this forum post? Should I post these as work-arounds?

3. You agreed that the issue of only one set of dropdown lists allowing a reversion to PLEASE SELECT is indeed a bug. Is it enough that you now know about it, or would it be helpful if I filed a bug report?

4. What about the issue of acceptance of partial responses? Is that considered a bug, or something to for Feature Requests?

Again, many thanks!
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 1 month ago #104278 by tpartner
Good, I'm glad to hear that it worked out.

In answer to your questions...

1) The XSS filter prevents you from entering a script when using the editor, it does not prevent the script from being rendered. If you turn on the filter and then go back and edit that question, the script will be dropped.

2) Sure, you can add these to the workarounds if you like. It's a wiki so anyone can play.

3) Yes, please file a bug report.

4) I would consider that a feature request.


.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose