Welcome to the LimeSurvey Community Forum

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

modifying "array dual scale" questions

  • jvandernoll
  • jvandernoll's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
11 years 1 week ago #93931 by jvandernoll
modifying "array dual scale" questions was created by jvandernoll
Hi there,
I have a question about the formatting of "array dual scale" questions.

I have a couple of questions where people have to decide whether to give answers on one or the other scale (the scaales have different consequences - with their answers participants are helping one person or the other). After having tried various things, using an "array dual scale" seems to be the best solution.

Based on another post on the forum ( www.limesurvey.org/en/forum/design-issue...n-range?limitstart=0 ) I created my question in the following order:

"scale 1 - question - scale 2"
I have attached a screenshot of an example question.




Now I would like to adjust the width of the question box, but I cannot find a solution to that (in the advanced settings you can change the "answer width" but that changes the width of the first column).

Also, I would like that people can only give one anwser - either scale 1 or scale 2
What I would basically need is what you have with "normal" radio buttons, that if you check a second radio button, it automatically unchecks the first one.

I tried this by making it a MaxDiff question ( docs.limesurvey.org/tiki-index.php?page=...axDiff_question_type ), where it is indeed possible to give one answer only, but then the problem is that people can not change their answer.

I figured both questions would have rather simple solutions - somewhere in the code, but I after numerous searches, I cannot find it.

Thanks for your help!
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
11 years 1 week ago #93935 by holch
Replied by holch on topic modifying "array dual scale" questions
No screenshot attached. Watch out for the file limits (I think it is something like 800x600px) or something.

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.
  • jvandernoll
  • jvandernoll's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
11 years 1 week ago - 11 years 1 week ago #93938 by jvandernoll
Replied by jvandernoll on topic modifying "array dual scale" questions
Oh, thanks, did not even notice it yet. Hope it works this way


Last edit: 11 years 1 week ago by jvandernoll. Reason: attach file
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
11 years 1 week ago - 11 years 1 week ago #93939 by holch
Replied by holch on topic modifying "array dual scale" questions
Hahahaha, now you can hardly see anything. ;-)

Try to cut out only the important question part and leave the rest out.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

Last edit: 11 years 1 week ago by holch.
The topic has been locked.
  • jvandernoll
  • jvandernoll's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
11 years 1 week ago - 11 years 1 week ago #93947 by jvandernoll
Replied by jvandernoll on topic modifying "array dual scale" questions
I keep on trying... :)
Somehow it is rally reluctant to upload my attachments - in the previews it is there, but in the submitted post it isn't ...
I've also attached (I hope..) the file that you get when you "export this question"
Last edit: 11 years 1 week ago by jvandernoll.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
11 years 1 week ago #93976 by tpartner
Replied by tpartner on topic modifying "array dual scale" questions
I've tweaked your script a bit to:

1) Automatically detect the question ID
2) Add a specific class to the question (that can be used in template.css)
3) Reset the column widths imposed by LimeSurvey
4) Only allow one radio checked per row

Code:
<script type="text/javascript" charset="utf-8">
  $(document).ready(function() { 
 
    moveRowLabels({self.qid});
 
    function moveRowLabels(qID) {
 
      // Add a class for the question
      $('#question'+qID).addClass('moveRowLabelsQ');
 
      // Hide the first column
      $('#question'+qID+' th.header_answer_text, #question'+qID+' th.answertext').hide();
 
      // Insert the subquestion text into the scale separators
      $('#question'+qID+' table.question tbody').each(function(i){
        $('.dual_scale_separator:eq(0)', this).text($('.answertext', this).text());
      });
 
      // Reset the column widths
      $('#question'+qID+' col').css({ 'width':'auto' });
 
      // Only one radio clicked allowed per row
      $('#question'+qID+' table.question input.radio').click(function() {
        var parentRow = $(this).closest('tr');
        $('.active', parentRow).removeClass('active');
        $(this).addClass('active');
        $('input.radio', parentRow).not('.active').attr('checked', false);
      });      
      $('#question'+qID+' table.question td.radio-item').click(function(event) {
        var parentRow = $(this).closest('tr');
        $('.active', parentRow).removeClass('active');
        $('input.radio', this).addClass('active');
        $('input.radio', parentRow).not('.active').attr('checked', false);
      });
    }
    });
</script>


Now you can add something like this to the end of template.css to set the column widths:
Code:
.moveRowLabelsQ td.answer-item { /* radio cells */
  width: 30px;
}
 
.moveRowLabelsQ td.information-item { /* question cell */
  width: 80px;
}


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: blacknail
The topic has been locked.
  • jvandernoll
  • jvandernoll's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
11 years 1 week ago #93978 by jvandernoll
Replied by jvandernoll on topic modifying "array dual scale" questions
Thanks a lot Tony!!

For the first part, it did not automatically detect the question ID, but once I filled that in in the place of {self.qid} it works perfectly. :-)

The second part does not work right away, I guess I need to take a little bit more time for that to figure the template.css language out.

Jolanda.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
11 years 1 week ago #93980 by tpartner
Replied by tpartner on topic modifying "array dual scale" questions

The second part does not work right away, I guess I need to take a little bit more time for that to figure the template.css language out.

Can you activate a test so we can see the source code?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • jvandernoll
  • jvandernoll's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
11 years 1 week ago #94007 by jvandernoll
Replied by jvandernoll on topic modifying "array dual scale" questions
With "activate a test" I assume you meant to activate a survey, right? I think I just use the standard template.

Here it is: tools.uclouvain.be/limesurvey191/index.php?sid=74427&lang=en

I noticed another thing, if I set the question to mandatory, I get an error that not all mandatory questions are answered (I guess that is because one of the scales is "missing" an answer). I would prefer to set the question as mandatory, or at least not to have the "no answer" box showing up. Any suggestions there?

Thanks again!
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
11 years 1 week ago #94010 by tpartner
Replied by tpartner on topic modifying "array dual scale" questions
Oh, I see you are using LS 1.91. My script modifications are for LS 2.0.

I'll need to rework a couple of things...

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
11 years 1 week ago #94021 by tpartner
Replied by tpartner on topic modifying "array dual scale" questions
Okay, in 1.92, set the question to non-mandatory and use this script. In addition to the above behaviour, it will:

1) Uncheck and hide the "No Answer" options
2) Pop up an alert and abort the submit function if a row is unanswered.
Code:
<script type="text/javascript" charset="utf-8">
  $(document).ready(function() {
 
    moveRowLabels({self.qid});
 
    function moveRowLabels(qID) {
 
      var alertMsg = 'One or more mandatory questions have not been answered. You cannot proceed until these have been completed.';
 
      // Add some classes
      $('#question'+qID).addClass('moveRowLabelsQ');
      $('#question'+qID+' table.question tbody td').not('.dual_scale_separator').addClass('answer-item radio-item');
 
      // Hide the first column
      $('#question'+qID+' th.header_answer_text, #question'+qID+' th.answertext').hide();
 
      // Uncheck and hide the "No Answer" columns
      $('#question'+qID+' .header_no_answer').hide().prev().hide('header_separator');
      $('#question'+qID+' input.radio[value=""]').attr('checked', false).closest('td').hide().prev().hide('header_separator');
 
      // Insert the subquestion text into the scale separators
      $('#question'+qID+' table.question tbody').each(function(i){
        $('.dual_scale_separator:eq(0)', this).text($('.answertext', this).text());
      });
 
      // Reset the column widths
      $('#question'+qID+' col').css({ 'width':'auto' });
 
      // Only one radio clicked allowed per row
      $('#question'+qID+' table.question input.radio').click(function() {
        var parentRow = $(this).closest('tr');
        $('.active', parentRow).removeClass('active');
        $(this).addClass('active');
        $('input.radio', parentRow).not('.active').attr('checked', false);
      });      
      $('#question'+qID+' table.question td.radio-item').click(function(event) {
        var parentRow = $(this).closest('tr');
        $('.active', parentRow).removeClass('active');
        $('input.radio', this).addClass('active');
        $('input.radio', parentRow).not('.active').attr('checked', false);
      });
 
      // At least one radio clicked per row
      // Interrupt the submit function
      $('#movenextbtn, #movesubmitbtn').click(function(){
        var error = 0;
        $('#question'+qID+' table.question tbody.error').removeClass('error');
        $('#question'+qID+' table.question tbody').each(function(i){
          if($('input.radio:checked', this).length == 0) {
            error = 1;
            $(this).addClass('error');
          }
        });
        if(error == 1) {
          alert(alertMsg);
          return false;
        }
      });
    }
    });
</script>

And then use something like this at the end of template.css:
Code:
.moveRowLabelsQ table.question tbody td.answer-item { /* radio cells */
  width: 30px;
}
 
.moveRowLabelsQ table.question  td.dual_scale_separator { /* question cell */
  width: 80px;
}
 
.moveRowLabelsQ table.question tbody.error td.answer-item { /* Error cells */
background: pink;
}

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