Skip to content

Model Object

addError()

addError() — returns void

Available in: model Category: Error Functions

Adds an error on a specific property.

NameTypeRequiredDefaultDescription
propertystringyes—The name of the property you want to add an error on.
messagestringyes—The error message (such as “Please enter a correct name in the form field” for example).
namestringno—A name to identify the error by (useful when you need to distinguish one error from another one set on the same object and you don’t want to use the error message itself for that).
// 1. Add an error to the `email` property.
this.addError(property="email", message="Sorry, you are not allowed to use that email. Try again, please.");

// 2. Add a named error so you can distinguish it from other errors on the same property.
this.addError(property="email", message="That email address is already taken.", name="emailTaken");

// 3. Check for the named error after adding it.
this.addError(property="username", message="Username is reserved.", name="reservedUsername");
if (this.hasErrors(property="username", name="reservedUsername")) {
	writeOutput("A reserved-username error is present.");
}