Skip to main content
tabishr9473
Participating Frequently
Jun 21, 2023 7:41 AM UTC
Question

Can I make a validation rule from local variables, like use operator?

a!localVariables(
  local!fieldName:"5",
  local!operator:">",
  local!value:"2",
  a!textField(
                value: fv!item.fieldName,
                saveInto: fv!item.fieldName,
                validations: {
                  a!validationMessage(
                    message:"test",
                    showWhen: local!fieldName & local!operator & local!value
                  )
                }
              )
  )

This is an example of what I want to achieve, the operators can be different, the fieldValues & fieldName can be of the other fields. I want the showWhen condition to work even if I give it a string.

4 replies

lavanyam0003
Known Participant
Jun 21, 2023 8:16 AM UTC

Showwhen will apply only when the result is true or false.
Could you please elaborate the exact requirement what to achieve.

tabishr9473
Participating Frequently
Jun 21, 2023 8:21 AM UTC

yes, I want the showWhen condition to be dynamic so that the conditional operators I use in it should be coming from a local variables & also for the left & right condition. e.g. I want to write "5>2" in showWhen but I have 3 local variables instead which will be:
 local!fieldName:"5",
local!operator:">",
local!value:"2",

So is there a way to do this because these variables values can change

sanchitg0002
Inspiring
Jun 21, 2023 8:26 AM UTC

a!match(
          value: local!operator,
          equals: ">",
          then: local!fieldName > local!value,
          equals: "=",
          then: local!fieldName = local!value,
          equals: "<",
          then: local!fieldName < local!value,
          /*....more operators*/
          default: {}
        )

mathieud0001
Genius
Jun 21, 2023 8:17 AM UTC

Not possible like this but I would suggest simply creating a rule (i.e rule!evaluateOperator) with 3 rules inputs (value 1, value 2 and operator) and run it through a a!match which will run the appropriate operator.