What's the best way to make an input of an app a required field only if a condition is met? I think the "required: true" field requires the field even if it is not shown.
So, for example,
input name: "condition", type: "bool"....
if (condition) {
input name: "selectiveRequirement", type: "text", required: ???
}
I want to make it a requirement only if the condition input is true, but optional if the condition input is false. Do I have to do post-input checking for this, or is there a better way?
I don’t believe you can put a condition within an input statement but you could duplicate that input declaration one making it required and one not with an if-else statement.
input name: "condition", type: "bool"....
if (condition) {
input name: "myField", type: "text", required: true
}
else {
input name: "myField", type: "text", required: false
}
Like this? Duplicate the name of the input too?
That’s correct and if your condition is based on another input, then at the end of that input include:
submitOnChange: true
This will make the page refresh so the value is set for your condition to re-evaluate.
1 Like
FWIW, I've done it the other way too:
input name: "myField", type: "text", required: (expression1 && !expression2)
(I'll repeat the note above that the submitOnChange: true
thing for the fields that affect expression1
and expression2
in my example above is important if these inputs are all on the same page)