Skip to content

Model Configuration

validateOnUpdate()

validateOnUpdate() — returns void

Available in: model Category: Validation Functions

Registers one or more validation methods that will be executed only when an existing object is being updated in the database. This allows you to enforce rules that apply strictly to updates, without affecting the creation of new records. You can also control whether the validation runs using the condition and unless arguments.

NameTypeRequiredDefaultDescription
methodsstringnoMethod name or list of method names to call. Can also be called with the method argument.
conditionstringnoString expression to be evaluated that decides if validation will be run (if the expression returns true validation will run).
unlessstringnoString expression to be evaluated that decides if validation will be run (if the expression returns false validation will run).
1. Basic usage: validate existing objects before update
function config() {
 validateOnUpdate("checkPhoneNumber");
}

function checkPhoneNumber() {
 // Ensure area code is '614'
 return Left(this.phoneNumber, 3) == "614";
}

2. Register multiple methods for validation on update
function config() {
 validateOnUpdate("checkPhoneNumber, checkEmailFormat");
}

function checkEmailFormat() {
 // Ensure email contains '@'
 return Find("@", this.email);
}

3. Conditional validation using `condition`
function config() {
 // Only validate phone number if the country is US
 validateOnUpdate("checkPhoneNumber", condition="this.country == 'US'");
}

4. Skip validation under certain conditions using `unless`
function config() {
 // Skip phone number validation if the user is an admin
 validateOnUpdate("checkPhoneNumber", unless="this.isAdmin");
}