Error

This class allows customizable errors to be displayed for each component when an error occurs.

These settings can also be specified in the Custom Errors panel of the Validation tab in the Builder.

The Error class has the following properties:

  • required
  • min
  • max
  • minLength
  • maxLength
  • invalid_email
  • invalid_date
  • pattern
  • custom

The values of these properties are the messages you wish to display once an error of that type occurs. Within the message, there are several values that you can use to include the component's label.

  • {{ field }}
  • {{ min }}
  • {{ max }}
  • {{ length }}
  • {{ pattern }}
  • {{ minDate }}
  • {{ maxDate }}
  • {{ minYear }}
  • {{ maxYear }}
  • {{ regex }}

The following example shows two custom error messages shown when a required component was left empty and when it does not have the minimum length:

Custom errors

The initialization code is as follows:

passwd = component.Password("passwd", form)
passwd.label = "Password"

validate = component_properties.Validate(passwd)
validate.required = True
validate.minLength = 8

error = component_properties.Error(passwd)
error.required = "Please provide a password."
error.minLength = "Password shall have at least {{ length }} characters."

ok = component.Button("ok", form)
ok.label = "Ok"
ok.disableOnInvalid = True
passwd = component.Password("passwd", form);
passwd.label = "Password";

validate = component_properties.Validate(passwd);
validate.required = true;
validate.minLength = 8;

error = component_properties.Error(passwd);
error.required = "Please provide a password.";
error.minLength = "Password shall have at least {{ length }} characters.";

ok = component.Button("ok", form);
ok.label = "Ok";
ok.disableOnInvalid = true;