Welcome to the LimeSurvey Community Forum

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

Validate a group of multiple choice questions - Group by Group Display

  • davebostockgmail
  • davebostockgmail's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
1 month 3 weeks ago #268017 by davebostockgmail
Please help us help you and fill where relevant:
Your LimeSurvey version: 5.6.68 (I know and we are looking to upgrade to the 6.x soon)
Own server or LimeSurvey hosting: Own Server
Survey theme/template: Custom 
==================

I have a series of questions that needs to be shown group by group .. 
Working on a menu builder type question where we have elements such as 
Protein ( contains Beef, Chicken etc) and must be single choice and randomised within the group
Vegatables ( contains Onions Mushrooms etc) can can be select up to 3 and again randomised with the group
Rice ( contains stick, brown, no rice) single choice and must be randomised

So the easiest way I have thought of to do this is to run the survey as group by group as this gives me the ability to control the input on each of the questions and randomise with fixed answers at the end and control the max inputs etc.

What I am struggling with here is the overall validation of the page .... I have tried include a hidden question at the end of the page that is mandatory and this allows me to continue with no answers I have also added validation to the last of the questions which counts the answers to all questions but that only works on the last question.

Is there a way I can validate a group by group page to ensure at least one answer is given?

On a secondary note the last group has a none of these that is exclusive and I would like that to remove all other selections on the page.

Any direction on this would be amazing, if it is not possible then I will have to come up with another approach.

thanks
Dave


 

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 month 3 weeks ago #268018 by Joffm
Hi, Dave,
best is you send the lss export of this part of your survey.

Joffm

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

Please Log in to join the conversation.

  • davebostockgmail
  • davebostockgmail's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
1 month 3 weeks ago #268023 by davebostockgmail
 

File Attachment:

File Name: limesurvey...4343.lss
File Size:90 KB
Here is the LSS file with the specific questions .. it needs to be show by Group to work in the style intended.thanksDave 

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 month 3 weeks ago #268025 by Joffm
Hi,
1. There is the question C4, where you can insert an error message.

2. Did you consider a multi level approach?
Like this (here with three levels, you only need two)
 
Very easy to validate

BUT:
Why is there the option "no answer". In each section there is "no rice", "no protein", ... So why "no answer"?
In my opinion each single section can be mandatory. Either I select something or I answer "No, I do not want to add this"

Joffm

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

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 month 3 weeks ago #268034 by Joffm
This is my proposal.
Multi (two) level

Check of each category (one or more possible selctions)
Check for "none"





If you are interested I will add some finetuning and send the lss.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: DenisChenu

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 month 3 weeks ago - 1 month 3 weeks ago #268037 by Joffm
Hi,
to come back to your first idea.

All questions set to "mandatory" (either you select some rice or "no rice")
And inserted the script to have this "no rice" option always at the end
Code:
<script type="text/javascript" charset="utf-8">    
 
    $(document).on('ready pjax:scriptcomplete',function(){
 
        // The number of answers to be fixed at the end of the list
        var fixedAnswers = 1;
 
        // Set this to "true" if you want "Other" to be fixed in the last position
        var otherFixed = false;
 
        // Identify this question
        var qID = {QID};
 
        // Find the number of answers
        var ansCount = $('#question'+qID+' .answer-item').length;
        if($('#question'+qID+' input[type="text"]').length > 0) {
            ansCount = ansCount -1
        }
        console.log(ansCount);
 
        // Place the last n answers created at the end of the list
        var fixedIndex = fixedAnswers - 1;
        for (var i=0; i<fixedAnswers; i++) {
            var answer = $('input[id^="answer"][id$="X'+qID+(ansCount-fixedIndex)+'"]');
            var answerItem = $(answer).closest('.answer-item');
            var answersList = $(answer).closest('ul');
            $(answersList).append(answerItem);
            fixedIndex--;
        }        
 
        // Handle "Other"
        if(otherFixed == true &amp;&amp; $('#question'+qID+' input[type="text"]').length > 0) {
            var otherAnswer = $('#question'+qID+' input[type="text"]');
            var otherAnswerItem = $(otherAnswer ).closest('.answer-item');
            var otherAnswersList = $(otherAnswer ).closest('ul');
            $(otherAnswersList).append(otherAnswerItem);
        }
    });
</script>

Furthermore you may randomize the categories with "randomization group name"

Then you can do this at the end:
count the numbers of "no protein", "no rice", ... (cntNo)
{sum(if(C4A.NAOK==7,1,0),if(C4B.NAOK==7,1,0),if(C4C.NAOK==5,1,0),if(C4D_9=="Y",1,0),if(C4E.NAOK==6,1,0),if(C4F_7=="Y",1,0))}
count the numbers of categories with selected options (cntCat)
{sum(if(!is_empty(C4A),1,0),if(!is_empty(C4B),1,0),if(!is_empty(C4C),1,0),if(count(that.C4D)>0,1,0),if(!is_empty(C4E),1,0),if(count(that.C4F)>0,1,0))}

Now you can display at the end
either (if cntNo==6)
 
or (if cntCat==6)
 

But anyway, your requirement is fulfilled.

Joffm

 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 month 3 weeks ago by Joffm.
The following user(s) said Thank You: DenisChenu

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose