Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
Update `requireIf` validator to include option to pass a UDF/closure. (coldbox-modules/cbvalidation#78)
  • Loading branch information
homestar9 authored Sep 8, 2023
1 parent c56674d commit 87c4e09
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion overview/valid-constraints/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,9 @@ myField = { required=false }

## requiredIf

The field under validation must be present and not empty if the `anotherfield` field is equal to the passed `value`. The validation data can be a `struct` or a `string` representing the field to check.
The field under validation must be present and not empty if the `anotherfield` field is equal to the passed `value`. The validation data can be a `struct` or a `string` representing the field to check, or it can be a UDF/closure/lambda to use for validation. The UDF must return **boolean**, `validate( value, target, metadata ):boolean`

Any data you place in the `metadata` structure will be set in the validation result object for later retrieval.

```javascript
// Struct based
Expand All @@ -547,6 +549,14 @@ myField = {
// myField is required if field3 exists and has a value.
requiredIf = "field3"
}

// UDF Based
myField = {
// myField is required if today is monday.
requiredIf = function( value, target, errorMetadata ) {
return dayOfWeekAsString( dayOfWeek( now() ) ) == "Monday";
}
}
```

## requiredUnless
Expand Down

0 comments on commit 87c4e09

Please sign in to comment.