Welcome to the LimeSurvey Community Forum

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

Make choosing the same option twice impossible: array by column

  • tammo
  • tammo's Avatar Topic Author
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
11 months 1 week ago #242600 by tammo
Please help us help you and fill where relevant:
Your LimeSurvey version: 5.6.13
Own server or LimeSurvey hosting: Own server
Survey theme/template: Extended version of Vanilla
==================
I just cannot seem to find it: how can I make it impossible to choose "Most favourable" and "Least favourable" for the same option?

 

research.respondage.com/index.php/668556?newtest=Y&lang=en

 


Tammo ter Hark at Respondage
For Limesurvey reporting, education and customized themes
respondage.nl

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
11 months 1 week ago #242610 by Joffm
Hi, @tammo
here's the "MaxDiff"  workaround
Code:
<script type="text/javascript" charset="utf-8">       
function maxDiff(qID, randomize) {
 
    // Identify some elements
    var thisQuestion = $('#question'+qID);
    var thisTable = $('table.subquestion-list:eq(0)', thisQuestion);
 
    // Assign a new question class
    $(thisQuestion).addClass('max-diff-array');
 
    // Move the columns
     $('thead tr:eq(0)', thisTable).prepend($('thead tr:eq(0) th:eq(1)', thisTable));
    $('tr.answers-list', thisTable).each(function(i){
    $('td.answer-item:eq(0)', this).prependTo(this);
    });
 
    // Random rows
    if(randomize) {
        var rowsArr = [];
        $('tr.answers-list', thisTable).each(function(i){
            $(this).attr('data-index', i);
            rowsArr.push(i);
        });
        shuffleArray(rowsArr);
        $(rowsArr).each(function(i){
            $('tbody', thisTable).append($('tr[data-index="'+this+'"]', thisTable));
        });
    }
 
    // Prevent clicking twice in the same row
    $('input[type="radio"]', thisQuestion).on('click', function () {
 
        $('input[type="radio"]', thisQuestion).prop('disabled', false);
        $('input[type="radio"]:checked', thisQuestion).each(function(i) {
            var thisRow = $(this).closest('tr.answers-list');
            $('input[type="radio"]', thisRow).not(this).prop('disabled', true);
        });
    });
 
    // Fix up the row classes
    var rowClass = 1;
    $('tr.answers-list', thisTable).each(function(i) {
        $(this).addClass('array'+(2-(i%2)));
    });
}
function shuffleArray(array) {
    for (var i = array.length - 1; i > 0; i--) {
        var j = Math.floor(Math.random() * (i + 1));
        var temp = array[i];
        array[i] = array[j];
        array[j] = temp;
    }
    return array;
}
  
  $(document).ready(function(){
        // Call the maxDiff() function
        // Set the second parameter to true for randomized rows
        maxDiff({QID}, true);
    });
</script>
<style type="text/css">.ls-answers tbody .answertext{
   text-align:center !important;
  }
</style>

 

 

File Attachment:

File Name: arraybycolumn_JK.lss
File Size:24 KB


Joffm

 

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • tammo
  • tammo's Avatar Topic Author
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
11 months 1 week ago #242616 by tammo
Hi Joffm,

I do appreciate this solution and will possibly use it, but is it really necessary to do this with Javascript?

Isn't there a solution thinkable using Expression script?

Tammo


Tammo ter Hark at Respondage
For Limesurvey reporting, education and customized themes
respondage.nl

Please Log in to join the conversation.

  • tammo
  • tammo's Avatar Topic Author
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
11 months 1 week ago - 11 months 1 week ago #242618 by tammo
And... bonus remark: when you want to change the width of the answer column, only the first answer column responds to the setting..... I guess that is also caused by the column shuffeling.


Tammo ter Hark at Respondage
For Limesurvey reporting, education and customized themes
respondage.nl
Last edit: 11 months 1 week ago by tammo.

Please Log in to join the conversation.

  • tammo
  • tammo's Avatar Topic Author
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
11 months 1 week ago #242624 by tammo
Turns out I was wrong: you can set the width of the answers column. That setting is being used for the first column.


Tammo ter Hark at Respondage
For Limesurvey reporting, education and customized themes
respondage.nl

Please Log in to join the conversation.

  • tammo
  • tammo's Avatar Topic Author
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
11 months 1 week ago #242625 by tammo
Getting into it.

Another trick: would it be possible to show at first only the first answer column and show the second one only when the first one has been answered?


Tammo ter Hark at Respondage
For Limesurvey reporting, education and customized themes
respondage.nl

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
11 months 1 week ago #242629 by Joffm
Hi, @tammo,
I have to admit, I have not the least idea.
Of course this script is originally by @tpartner.

I only showed it in one of my tutorials.

Joffm
 

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • tammo
  • tammo's Avatar Topic Author
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
11 months 1 week ago #242632 by tammo
Your tutorials are great. Please make them available through a link in your signature (and translate them in Dutch (or English for the people that do not speak Dutch!))

Tammo


Tammo ter Hark at Respondage
For Limesurvey reporting, education and customized themes
respondage.nl
The following user(s) said Thank You: DenisChenu

Please Log in to join the conversation.

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
11 months 1 week ago - 11 months 1 week ago #242642 by DenisChenu

I do appreciate this solution and will possibly use it, but is it really necessary to do this with Javascript?

 
It was done before we have QuestionTheme
I think it can be done directly in HTML now.

Maybe ask at @tparner ?

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Last edit: 11 months 1 week ago by DenisChenu.

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose