Required result:
A forms::form component becomes invalid as part of front-end validation when some components hold a certain combination of values: in the example, a Text Field will be valid only if another Text Field contains a correct value and if the combination of the values of the fields is valid.
a
and b
.//rules for validation of the fields: private void validateGroup(){ //error message for field a: def String error1 := (a.getValue() == "1" and b.getValue()== "1") ? "Values must not equal 1." : null; //error message for field b: def String error2 := (b.getValue()== "3") ? "b value must not equal 3." : null; def String all := joinErrors(error1, error2); //setting the errors as custom error messages on a: if !all.isBlank() then a.setCustomErrorMessage(all); else a.setCustomErrorMessage(null) end } //concatenate errors from components: private String joinErrors(String... errors) { def String concatenated := join(errors, "<br>"); concatenated.isEmpty() ? null : concatenated; }
//Init on text fields:
c.setOnChangeListener({ e ->
validateGroup()
})