Validation

You can use our one of predefined patterns to validate the field. If you want to make your own validation you can do it easily also.

List of predefined:

  • EmailValidation
  • IPAddressValidation
  • PhoneValidation
  • UrlValidation

Simple validation

If you want to validate the field with pattern that is not connected with other fields you should use RowValidation class. It's easy to configure.

Example of the value validation for text that should be longer than 7 characters:

1
2
3
4
5
6
    Validation validation = new RowValidation("Field", "Text should be longer - Error Msg") {
            @Override
            public boolean validateView(JSONObject value) {
                return value.optString("value").length() > 7;
            }
        };

How to add it to the action view:

1
    .addValidation(groupValidation, ValidationMode.ON_SUBMIT)

You have to execute it on the row object.

Dependent validation

If your validation has to know about other elements it is the proper solution for you.

Example validation to check that the switch with id agreement and the our validated switch element are switched. If both are switched validation will be successful.

1
2
3
4
5
6
final Validation depValidation = new DependentValidation(formView, "Error Msg") {
            public boolean validate(GSDFormView formView, JSONObject value) {
                Row row = formView.getRowById("agreement");
                return value.optBoolean("value") && row.getActionView().getValue().optBoolean(row.getActionView().getDefaultValueField());
            }
        };

It's more complicated, but gives you possibility to build dynamic validations without the limits.