If true
validates that the given value is not empty, if false
, validates that the given value is empty.
Examples
validator('presence', true)
validator('presence', false)
validator('presence', {
presence: true,
message: 'should not be empty'
})
validator('presence', {
presence: true,
ignoreBlank: true,
message: 'should not be empty or consist only of spaces'
})
buildOptions
(
Object
-
options
-
defaultOptions
-
globalOptions
Normalized options passed in.
validator('presence', true)
// Becomes
validator('presence', {
presence: true
})
Returns:
createErrorMessage
(
String
-
type
-
value
-
options
Used by all pre-defined validators to build an error message that is present
in validators/message
or declared in your i18n solution.
If we extended our default messages to include uniqueUsername: '{username} already exists'
,
we can use this method to generate our error message.
validate(value, options) {
var exists = false;
get(options, 'description') = 'Username';
get(options, 'username') = value;
// check with server if username exists...
if(exists) {
return this.createErrorMessage('uniqueUsername', value, options);
}
return true;
}
If we input johndoe
and that username already exists, the returned message would be 'johndoe already exists'
.
Parameters:
Returns:
String:
The generated message
getValue
()
Mixed
private
Wrapper method to value
that passes the necessary parameters
Returns:
Mixed:
value