Javascript : Regex Validator with expression

1 week ago 17
ARTICLE AD BOX

I am trying to validate the input based on previous selection using SurveyJS. The input in last section of Duration should depend on previous selection of Days or Months or Years.

If I keep only condition in validation it works fine but when I add more than 1 condition it is trying to validate against all 3 irrespective of expression condition.

Below JSON can be used in Survey JS codepen or codesandbox:

{ "pages": [ { "name": "page1", "elements": [ { "type": "radiogroup", "name": "Gym", "title": "Do you go to GYM", "isRequired": true, "choices": [ "Yes", "No" ] }, { "type": "radiogroup", "name": "GymDur", "visibleIf": "{Gym} = 'Yes'", "title": "How long have you been going to GYM", "resetValueIf": "{Gym} = 'No'", "isRequired": true, "choices": [ "Days", "Months", "Years" ] }, { "name": "GymDura", "type": "text", "title": "Enter Duration", "inputType": "number", validators: [ { type: "regex", regex: "^(?:[0-9]|[1-2][0-9])$", text: "Value should be less than 29.99", expression: "{GymDur} = 'Days'", }, { type: "regex", regex: "^(?:[0-9]|1[01])$", text: "Value should be less than 11.99", expression: "{GymDur} ='Months'", }, { type: "regex", regex: "^(?:d{1,2})(?:.d{1,2})?$", text: "Value should be less than 99.99", expression: "{GymDur} ='Years'", }, ], }, ], } ], }

Is there any way we can have validators work based on the single expression inputs (Days, Months and Years) only and if I change the value if Input (Days to Months or Year) the data and validation error in Enter Duration should automatically get reset.

Read Entire Article