Skip to content

Model Configuration

validatesInclusionOf()

validatesInclusionOf() — returns void

Available in: model Category: Validation Functions

Validates that the value of the specified property exists in the supplied list.

NameTypeRequiredDefaultDescription
propertiesstringno—Name of property or list of property names to validate against (can also be called with the property argument).
liststringyes—List of allowed values.
messagestringno[property] is not included in the listSupply a custom error message here to override the built-in one.
whenstringnoonSavePass in onCreate or onUpdate to limit when this validation occurs (by default validation will occur on both create and update, i.e. onSave).
allowBlankbooleannofalseIf set to true, validation will be skipped if the property value is an empty string or doesn’t exist at all. This is useful if you only want to run this validation after it passes the validatesPresenceOf test, thus avoiding duplicate error messages if it doesn’t.
conditionstringno—String expression to be evaluated that decides if validation will be run (if the expression returns true validation will run).
unlessstringno—String expression to be evaluated that decides if validation will be run (if the expression returns false validation will run).
// 1. Validate that a user selects a valid framework choice
validatesInclusionOf(property="frameworkOfChoice", list="cfwheels,rails,django", message="Please select a supported framework.");

// 2. Validate a status field and skip validation if the value is blank
validatesInclusionOf(property="status", list="active,inactive,pending", allowBlank=true);

// 3. Validate a role only when creating a new record
validatesInclusionOf(property="role", list="admin,editor,viewer", when="onCreate");

// 4. Validate a priority field only when a condition is met
validatesInclusionOf(property="priority", list="low,medium,high", condition="this.isAssigned()");