Skip to content

Model Object

errorsOn()

errorsOn() — returns array

Available in: model Category: Error Functions

Returns an array of all errors associated with the supplied property (and error name if passed in).

NameTypeRequiredDefaultDescription
propertystringyes—Specify the property name to return errors for here.
namestringno—If you want to return only errors on the property set with a specific error name you can specify it here.
// 1. Get all errors associated with the emailAddress property
errors = user.errorsOn("emailAddress");
// errors -> [{property: "emailAddress", message: "is invalid", name: ""}, ...]

// 2. Get only errors on emailAddress that were set with a specific error name
errors = user.errorsOn(property="emailAddress", name="formatCheck");
// errors -> [{property: "emailAddress", message: "must be a valid email", name: "formatCheck"}]

// 3. Check errors on a property and loop over them
errors = user.errorsOn("username");
for (error in errors) {
    writeOutput(error.message);
}