Welcome to the LimeSurvey Community Forum

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

Make none mandatory comment mandatory based on likert scale selection

  • kohuke
  • kohuke's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 9 months ago - 4 years 9 months ago #186166 by kohuke
I might sound dumb, but how do I achieve the following result:

A question group contains 2 questions - one of them is likert scale and other is a comment field. How can I make comment field mandatory if the participant has selected even one answer option which is highlighted with yellow on screenshot?

Right now the comment question is not mandatory. I tried to follow the instructions here: www.limesurvey.org/es/foro/can-i-do-this...put-if-answer-equals , but when I tried to have the "==" either the lable of the answer option or the code of the answer option the question didn't go mandatory.
I am also reading the manual: manual.limesurvey.org/Expression_Manager#Access_to_Variables , but again I am not really understanding how can I make what I need happen :(

That much I know that I can make the comment show or be hidden if a certain answer option is selected, however I do want the comment field always be present so I don't think I can achieve it with conditions.
Last edit: 4 years 9 months ago by kohuke.
The topic has been locked.
More
4 years 9 months ago #186180 by jelo

kohuke wrote: That much I know that I can make the comment show or be hidden if a certain answer option is selected, however I do want the comment field always be present so I don't think I can achieve it with conditions.


You can make the comment field mandatory via the Logic section in the advanced settings of the text/comment field.
A bit ExpressionScript (ExpressionManager) knowhow is needed. You already pointed to a thread where that is shown.

Please create a survey (LSS export) with your the two questions and attach that here. And what LimeSurvey version is used?

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The topic has been locked.
  • kohuke
  • kohuke's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 9 months ago #186185 by kohuke
I did an export of one of the survey groups (I have more with the same option needed). Hopefully this is enough.


Version 3.17.3+190429 should be the version.

Sadly this is the first time I am asked to have that kind of check in place and hopefully someone can dumb it down so I can do what is asked.
The topic has been locked.
More
4 years 9 months ago #186192 by jelo
Always export LSS (complete example). If you export a LSQ, other will need to create a new survey, check for the correct language to be able to import the LSQ and it still differ from your survey.

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The topic has been locked.
  • kohuke
  • kohuke's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 9 months ago #186194 by kohuke
Thank you for the explanation and sorry. Here's the full survey.

File Attachment:

File Name: limesurvey...4468.lss
File Size:106 KB
The topic has been locked.
  • kohuke
  • kohuke's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 9 months ago #186254 by kohuke
I have been experimenting with some strings:
Code:
K2Kom.mandatory=if(K2_SK2Q001 == "Ei ole nõus", "")
where K2Kom = comment question itself, K2_SK2Q001 = question and "Ei ole nõus" = answer option. But when I select just the 1st answer to have the "ei ole nõus" option and rest with something else it still jumps to next question when everything else is selected.
When I tried to add all of the subquestion to make comment mandatory if the answer option is shown I get told that invalid code
Code:
K2Kom.mandatory=if((K2_SK2Q001 == "Ei ole nõus", "") OR (K2_SK2Q002 == "Ei ole nõus", "") OR (K2_SK2Q003 == "Ei ole nõus", "") OR (K2_SK2Q004 == "Ei ole nõus", "") OR (K2_SK2Q005 == "Ei ole nõus", "") OR (K2_SK2Q006 == "Ei ole nõus", ""))
Can anyone assist? Cause I am really lost :(
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 9 months ago - 4 years 9 months ago #186267 by tpartner
When providing sample surveys, please only include the relevant questions. The volunteers giving help here do not have time to go threw a bunch of survey questions only to find that they have nothing to do with the problem.

Expression Manager uses question/sub-question/answer codes, not the labels.

You can test whether any row in the array is answered with one of the first two items with an equation like this:

Code:
sum(countifop("==", 'K2K01', that.K2), countifop("==", 'K2K02', that.K2)) > 0

This effectively says return a sum of all of the K2 sub-questions having an answer equaling "K2K01" or "K2K02".

Please refer to the Expression Manager documentation for available functions - manual.limesurvey.org/Expression_Manager#Access_to_Functions

So, the Question validation equation for the comment question could be like this (line-breaks inserted for clarity):

Code:
(sum(countifop("==", 'K2K01', that.K2), countifop("==", 'K2K02', that.K2)) > 0 AND !is_empty(K2Kom))
OR
sum(countifop("==", 'K2K01', that.K2), countifop("==", 'K2K02', that.K2)) == 0

And, the Question validation tip could be like this (line-breaks inserted for clarity):

Code:
{
  if(
    (sum(countifop("==", 'K2K01', that.K2), countifop("==", 'K2K02', that.K2)) > 0 AND !is_empty(K2Kom)) 
    OR 
    sum(countifop("==", 'K2K01', that.K2), countifop("==", 'K2K02', that.K2)) == 0, 
    'Valid', 
    'Invalid!'
  )
}

Sample survey attached:

File Attachment:

File Name: limesurvey...4681.lss
File Size:69 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 4 years 9 months ago by tpartner.
The topic has been locked.
  • kohuke
  • kohuke's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 9 months ago #186272 by kohuke
Thank you very much for the assistance and the explanations. I didn't think that those things should be placed under "Logic" section, furthermore to use a "mathematical" function.
I got to modify all of my question I needed as well as gotten a decent idea on how to accommodate this function to other things if needed.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose