# new ReadOnlyValidator(value, oldValue, messageopt)
Validator for the readonly
decorator that checks if a value has been changed during an update operation. It compares the new value with the old value and returns an error message if they are not equal.
A validator that ensures properties marked as readonly cannot be modified during updates.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
value |
any
|
The value to be validated |
|
oldValue |
any
|
The previous value to compare against |
|
message |
string
|
<optional> |
Optional custom error message |
Example
// Using ReadOnlyValidator with a readonly property
class User {
Methods
# hasErrors(value, args) → {string|undefined}
This method is required by the Validator interface but not used in this validator as validation only happens during updates.
Implementation of the base validator's hasErrors method.
Parameters:
Name | Type | Description |
---|---|---|
value |
any
|
The value to validate |
args |
Array.<any>
|
Additional arguments |
Always returns undefined as this validator only works during updates
string
|
undefined
# updateHasErrors(value, oldValue, messageopt) → {string|undefined}
Validates a value has not changed by comparing it with the previous value using deep equality.
Checks if a value has been modified during an update operation.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
value |
any
|
The new value to validate |
|
oldValue |
any
|
The original value to compare against |
|
message |
string
|
<optional> |
Optional custom error message to override the default |
An error message if validation fails, undefined otherwise
string
|
undefined