NAME
Valiant::Validator::Acceptance - Verify that a value was accepted
SYNOPSIS
package Local::Test::Acceptance;
use Moo;
use Valiant::Validations;
has terms_of_service => (is=>'ro');
validates terms_of_service => ( acceptance => 1 );
my $object = Local::Test::Acceptance->new(terms_of_service=>0);
$object->validate;
warn $object->errors->_dump;
$VAR1 = {
'terms_of_service' => [
'Terms Of Service must be accepted',
]
};
DESCRIPTION
Validates that a value is one of a set of accepted values, typically used for a "terms of service" checkbox or similar agreement field. The value must be defined and appear in the accept list; an undefined value fails (use the shared allow_undef parameter if you need undef to pass).
The attribute is usually a virtual one that exists only to hold the submitted form value and is not persisted.
CONSTRAINTS
This validator supports the following constraints.
- accept
-
An arrayref of the values considered acceptance. Defaults to
['1', 1, 'true', 'yes'].validates terms_of_service => ( acceptance => { accept => ['on'] }, ); - accepted
-
The error message used when the value is not accepted. Default is translation tag 'accepted'.
SHORTCUT FORM
This validator supports the follow shortcut forms:
validates attribute => ( acceptance => 1, ... );
Which is the same as:
validates attribute => (
acceptance => +{},
);
Not a lot of saved typing but it seems to read better.
GLOBAL PARAMETERS
This validator supports all the standard shared parameters: if, unless, message, strict, allow_undef, allow_blank.
SEE ALSO
Valiant, Valiant::Validator, Valiant::Validator::Each.
AUTHOR
See Valiant
COPYRIGHT & LICENSE
See Valiant