Welcome to the LimeSurvey Community Forum

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

RegexMatch and Min/Max answer queries

  • Matadeleo
  • Matadeleo's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
8 years 1 month ago - 8 years 1 month ago #152290 by Matadeleo
RegexMatch and Min/Max answer queries was created by Matadeleo
Hi, I'm looking to see if I can do 2 things with LimeSurvey:

1) I have a multi-numeric slider question, with min-max limits. Is it possible to use the "sum" value from this question, as the maximum amount of answers someone can select in the following question?

E.g.

Q1. How many bars did you eat? (User enters total sum of 3 out of possible 5)

Q2. How many did you enjoy? (Maximum answers dynamically reduced to 3 from 5)



2) The second query is: What is the syntax for targeting multiple subquestions with a regexMatch?

To target a single subquestion, I'm using the following:

- Question validation equation: (regexMatch('/([A-Z]{1}\d{1,2})/',Q24_1))
- Question validation tip: {if((regexMatch('/([A-Z]{1}\d{1,2})/', Q24_1)),'','Please enter a valid grid reference.')}

Ideally it would be something like this (this example breaks the syntax):
(regexMatch('/([A-Z]{1}\d{1,2})/',Q24_1, Q24_2, Q24_3, Q24_4, Q24_5, Q24_6))

I've attached the lss file for what I'm trying to get working

File Attachment:

File Name: example.lss
File Size:19 KB
Attachments:
Last edit: 8 years 1 month ago by Matadeleo.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 1 month ago #152300 by tpartner
Replied by tpartner on topic RegexMatch and Min/Max answer queries
1) If you place the two sliders on separate pages, you can use the value of Q1 as the "Slider maximum value:" for Q2.


2) Why not use the "Sub-question validation equation:"?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • Matadeleo
  • Matadeleo's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
8 years 1 month ago - 8 years 1 month ago #152301 by Matadeleo
Replied by Matadeleo on topic RegexMatch and Min/Max answer queries

1) If you place the two sliders on separate pages, you can use the value of Q1 as the "Slider maximum value:" for Q2.


Sorry, this wasn't what I meant. The slider question is fine, but we wish to use the SUM (Slider 1 + Slider 2 = SUM) value of both sliders as the Maximum answers in the short free text question.

There is 2 questions in the example - Q1 with 2x slider and Q2 multiple short text. We wish to set Q2 to Min answers 1 and Max answers to {Q1:SUM}.

2) Why not use the "Sub-question validation equation:"?


I was asking what the syntax for this would be:

I have tried to change this formula
Code:
(regexMatch('/([A-Z]{1}\d{1,2})/',Q24_1))
{if((regexMatch('/([A-Z]{1}\d{1,2})/', Q24_1)),'','Please enter a valid grid reference.')}

to this:
Code:
(regexMatch('/([A-Z]{1}\d{1,2})/'))
{if((regexMatch('/([A-Z]{1}\d{1,2})/')),'','Please enter a valid grid reference.')}

And using that code in the sub-question validation instead.

But I get syntax error, and I can't find any info on what the syntax for this would be.
Last edit: 8 years 1 month ago by Matadeleo.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 1 month ago #152306 by tpartner
Replied by tpartner on topic RegexMatch and Min/Max answer queries
Ah, in that case, I would make the following changes:
  • Remove the minimum and maximum settings from the slider question - these are set in the slider settings.
  • Place default answers of "1" on the slider question - this helps with relevance in the next step.
  • Place relevance on the Q2 subquestions to only show them if the slider sum is above a certain value. For example, the relevance for Q2_3 would be:
    Code:
    sum(Q1_1, Q1_2) > 2
  • Use this as the "Sub-question validation equation:" for Q2:
    Code:
    this.relevanceStatus != 1 OR regexMatch('/^([A-Z]{1}\d{1,2})$/', this.NAOK)

This all works well in the attached survey except there seems to be a bug with the "Sub-question validation tip" when sub-question relevance is used - I cannot get it to toggle between the two text values.

File Attachment:

File Name: limesurvey...6898.lss
File Size:20 KB

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: Matadeleo
The topic has been locked.
  • Matadeleo
  • Matadeleo's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
8 years 1 month ago #152341 by Matadeleo
Replied by Matadeleo on topic RegexMatch and Min/Max answer queries
Thanks for this Tpartner, working great for me. I was using an old version of limesurvey which didn't have relevance equation on a subquestion level (at least I didn't see it)
The topic has been locked.
  • Matadeleo
  • Matadeleo's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
8 years 1 month ago #152392 by Matadeleo
Replied by Matadeleo on topic RegexMatch and Min/Max answer queries
Do you know if it's possible to also add a condition to this, to prevent duplicate answers in the multiple short text?

At the moment, someone could potentially enter A1 in all cells - I would like to extend the current code to prevent that if possible.

I've attempted to write/find a regexmatch format for catching duplicates but with no luck
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 1 month ago - 8 years 1 month ago #152397 by tpartner
Replied by tpartner on topic RegexMatch and Min/Max answer queries
You can use the unique function in the "Question validation equation":
Code:
unique(self.NAOK)

www.limesurvey.org/manual/Expression_Man...#Access_to_Functions

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 8 years 1 month ago by tpartner.
The following user(s) said Thank You: Matadeleo
The topic has been locked.
  • Matadeleo
  • Matadeleo's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
8 years 1 month ago #152400 by Matadeleo
Replied by Matadeleo on topic RegexMatch and Min/Max answer queries
Thanks for the reply tpartner, I mentioned that would like to extend the current setting we have - so we can use the function but we aren't sure of the syntax to use to have multiple functions in the question validation equation (QVE).

Current QVE:
Code:
this.relevanceStatus != 1 OR regexMatch('/^([A-Z]{1}\d{1,2})$/', this.NAOK)

Example of desired QVE:
Code:
unique(self.NAOK) AND (this.relevanceStatus != 1 OR regexMatch('/^([A-Z]{1}\d{1,2})$/', this.NAOK))

Is it possible to merge the functions in this way so we keep the existing functionality of regexMatch, but can also force unique responses?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 1 month ago - 8 years 1 month ago #152403 by tpartner
Replied by tpartner on topic RegexMatch and Min/Max answer queries
As stated, you need to use unique(self.NAOK) in the "Question validation equation", not in the "Sub-question validation equation". This effectively says "all relevant sub-questions of this question must be unique".


Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 8 years 1 month ago by tpartner.
The following user(s) said Thank You: Matadeleo
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose