Willkommen, Gast
Benutzername: Passwort: Angemeldet bleiben:

THEMA: Expression Manager: Use Expressions in Validation field

Expression Manager: Use Expressions in Validation field 2 Jahre 6 Monate her #72366

  • Steve
  • Steves Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 494
  • Dank erhalten: 46
  • Karma: 17
Hello,

in the "LS2 Validation Samples" survey it looks like you can use Expressions in the validation field.
Relevance [Validation] (Default)
 
(VALIDATION: ((is_empty(minSelect) || minSelect >= (0)) and (is_empty(minSelect) || minSelect <= (5))))

Is it really possible to use Expressions from EM (not Regex) in this field or is it only a mapping EM does to the options set in den advance question settings?

If it is possible, can some please provide one or more exmaples. I thought about things like
is_empty(minSelect)
or
is_int(minSelect)
or even more complex things like
if(!is_empty(otherQuestion), 1 , 0)
(I don't know if you write true/false as 1/0 , true/false or "true"/"false") or something else.
Mit freundlichen Grüßen/Best regards,

Stefan Gohlke
LimeSurvey Team
Letzte Änderung: 2 Jahre 6 Monate her von Steve.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Expression Manager: Use Expressions in Validation field 2 Jahre 6 Monate her #72370

  • TMSWhite
  • TMSWhites Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 759
  • Dank erhalten: 82
  • Karma: 36
vierundzwanzig-

The validation examples you are seeing are auto-generated from advanced question attributes like min_value/max_value, etc.

The "validation" field in LS is always a regular expression (it maps to the 'preg' field in the questions table).

However, my plan has always been to divide validation like this:
(1)Rename "validation" to "Validation (Regular Expression)"
(2)Add "Validation (Equation)"

Then, EM would AND together all of the validation components (e.g. the auto-generated ones, the regular expression ones, and any newly added ones).

/Tom
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Expression Manager: Use Expressions in Validation field 2 Jahre 6 Monate her #72400

  • Steve
  • Steves Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 494
  • Dank erhalten: 46
  • Karma: 17
That sounds good, I'm looking forward to seeing it. Perhaps it might also be an alternative for people not familar with regex.
Mit freundlichen Grüßen/Best regards,

Stefan Gohlke
LimeSurvey Team
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Expression Manager: Use Expressions in Validation field 2 Jahre 6 Monate her #72405

  • Mazi
  • Mazis Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 5302
  • Dank erhalten: 291
  • Karma: 247
vierundzwanzig schrieb:
That sounds good, I'm looking forward to seeing it. Perhaps it might also be an alternative for people not familar with regex.
I think there are only 8-10 people out there who are really familiar with regular expressions :-)

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Expression Manager: Use Expressions in Validation field 2 Jahre 6 Monate her #72455

  • TMSWhite
  • TMSWhites Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 759
  • Dank erhalten: 82
  • Karma: 36
TMSWhite schrieb:
vierundzwanzig-
However, my plan has always been to divide validation like this:
(1)Rename "validation" to "Validation (Regular Expression)"
(2)Add "Validation (Equation)"

vierundzwanzig -

I've added this feature to limesurvey_dev (revision 12142), so it will be available in 1.92 RC3 (and 2.0)

There are two separate equation-based validations so that you can apply the same validation to every sub-question, and/or a separate equation to the whole question.

To make life easier, those equations use a reserved variable "this", and EM replaces "this" with the actual variable name when it auto-composed the validation equations.

So, as a silly example, I have a numeric question asking how much a person will donate to LimeSurvey, and they must say at least $50.00:

The regular expression validation is:
/^\$?\d+(\.(\d2))?$/

This lets people enter values like $75 or 50.00. Since I'm letting them prefix the value with the dollar sign, I can't use a simple min_value_n comparison. So, The em_validation_q would be:
if(is_numeric(this), this > 50, substr(this, 1) > 50)

/Tom
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Expression Manager: Use Expressions in Validation field 2 Jahre 6 Monate her #72524

  • Steve
  • Steves Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 494
  • Dank erhalten: 46
  • Karma: 17
Hello Tom,

I tried to create a question/answer with the donate example (LimeSurvey 1.92RC2 Build 12162 from SVN). If you want to enter a "$" sign the validation for the numeric question type seems to prevent you from entering anything that is not a number. It doesn't seem to matter if you set "Integer only" to "Yes" or "No".

The expression seems to work but if I'm correct it only works for the numeric input question type at the moment. I tried using a short free text with the same expression and the "Question Validation Equation" and "Question Validation Tip" don't work. There's no tip and it doesn't matter what you enter, it seems to be always true.

There seems to be no option to hide the "Question Validation Tip". If you enter a custom tip it also looks kind of strange:
"The question must meet these criteria: Please donate at least $50.00."
Perhaps we can overriede the "The question must meet these criteria:" if a "Question Validation Tip" is set/used.

If you want to use expressions in the question text or answer you have to use curly braces. But if you use them in the advance question settings you don't use them. This might confuse some users because there is no hint telling them that you don't use curly braces in here.
Anhang:
Mit freundlichen Grüßen/Best regards,

Stefan Gohlke
LimeSurvey Team
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Expression Manager: Use Expressions in Validation field 2 Jahre 6 Monate her #72570

  • TMSWhite
  • TMSWhites Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 759
  • Dank erhalten: 82
  • Karma: 36
vierundzwanzig schrieb:
I tried to create a question/answer with the donate example (LimeSurvey 1.92RC2 Build 12162 from SVN). If you want to enter a "$" sign the validation for the numeric question type seems to prevent you from entering anything that is not a number. It doesn't seem to matter if you set "Integer only" to "Yes" or "No".

The expression seems to work but if I'm correct it only works for the numeric input question type at the moment. I tried using a short free text with the same expression and the "Question Validation Equation" and "Question Validation Tip" don't work. There's no tip and it doesn't matter what you enter, it seems to be always true.

Not sure why it didn't work for you. Here is a working version using Short Text. You are correct that you can't enter a dollar sign in a Numeric Question type.

Dateianhang:

Dateiname: limesurvey_question_48.lsq
Dateigröße: 7 KB

vierundzwanzig schrieb:
There seems to be no option to hide the "Question Validation Tip". If you enter a custom tip it also looks kind of strange:
"The question must meet these criteria: Please donate at least $50.00."
Perhaps we can overriede the "The question must meet these criteria:" if a "Question Validation Tip" is set/used.

Since there are many different possible validation tips now (related to min/max answers; min/max values for each answer; min/max/equals values for sum of answers; regular expression validation; equation-based validation), we may want to extend the functionality of "hide_tip" to let users specify which types of tips they want to show/hide. You are correct that at the moment, those tips can not be hidden, but that is an easy coding change if, for example, the community says we should never show the regular expression or equation-based validation equations, instead requiring people to enter something into "help" to explain the validation in human-readable terms.
vierundzwanzig schrieb:
If you want to use expressions in the question text or answer you have to use curly braces. But if you use them in the advance question settings you don't use them. This might confuse some users because there is no hint telling them that you don't use curly braces in here.

You are correct, and I need to update the documentation. You ONLY use curly braces in question/answer/help text. You don't use curly braces in the relevance equation, or any of the advanced question settings.

The reason for this is that relevance and advanced question settings are always expressions. Curly braces are only used to separate display strings from expressions.

-Tom
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Expression Manager: Use Expressions in Validation field 2 Jahre 6 Monate her #72596

  • Steve
  • Steves Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 494
  • Dank erhalten: 46
  • Karma: 17
Hello Tom,

the difference between your question and my question seems to be that I'm only using the "Question Validation Equation" while you are using "Validation" AND "Question Validation Equation". Perhaps that is the problem, if I add the "Validation" the solution works fine. Though it then isn't a good solution if you don't know how to use regular expressions.

Okay, let's have a look at the tips. I think tips related to min/max answers, min/max values for each answer and min/max/equals values for sum of answers are things that a person without technical knowledge can understand. But I don't think people without technical or even programming logic will understand regular expressions like "/^\$?\d+(\.(\d{ 2 }))?$/" or equation-based validation equations like "if(is_numeric(this), this > 50, substr(this, 1) > 50)". So it might be a good idea to hide these tips if no "personal" message is set/specified. Perhaps there might be a neutral tip saying "Your answer doesn't meet the required criteria." and perhaps even "Please contact xy for further information".

I just noticed, there seems to be an error in the sentence
"The question must meet these criteria". It's the answer that should meet the criteria.
Mit freundlichen Grüßen/Best regards,

Stefan Gohlke
LimeSurvey Team
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Expression Manager: Use Expressions in Validation field 2 Jahre 6 Monate her #72615

  • Mazi
  • Mazis Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 5302
  • Dank erhalten: 291
  • Karma: 247
vierundzwanzig schrieb:
Okay, let's have a look at the tips. I think tips related to min/max answers, min/max values for each answer and min/max/equals values for sum of answers are things that a person without technical knowledge can understand. But I don't think people without technical or even programming logic will understand regular expressions like "/^\$?\d+(\.(\d{ 2 }))?$/" or equation-based validation equations like "if(is_numeric(this), this > 50, substr(this, 1) > 50)". So it might be a good idea to hide these tips if no "personal" message is set/specified. Perhaps there might be a neutral tip saying "Your answer doesn't meet the required criteria." and perhaps even "Please contact xy for further information".

I just noticed, there seems to be an error in the sentence
"The question must meet these criteria". It's the answer that should meet the criteria.
I agree to that. We should avoid too technical error messages because only some few users wil be able to deal with them.

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Expression Manager: Use Expressions in Validation field 2 Jahre 6 Monate her #72926

  • Fred
  • Freds Avatar
  • OFFLINE
  • Gold Lime
  • Beiträge: 163
  • Dank erhalten: 5
  • Karma: 3
Hi, this may be redundant with some of the discussion above. Sorry if so...

Are question input validation settings still supposed to generate the automatic tips in survey?

I have a multiple numeric input question.
In advanced question setting, under Input "equals sum value" is set to 100.

When I run the question in 1.91 it shows these tips:
"Only numbers may be entered in these fields
Total of all entries must not exceed 100"

When I run the question in 1.92 it only shows the first tip:
"Only numbers may be entered in these fields"
Der Administrator hat öffentliche Schreibrechte deaktiviert.
Moderatoren: ITEd
Ladezeit der Seite: 0.285 Sekunden
Donation Image