| Form-Factory documentation | Contained in the Form-Factory distribution. |
Form::Factory::Feature::Control::MatchAvailableChoices - Check for choice availability
version 0.020
has_control time_zone => (
control => 'select_one',
options => {
available_choices => [
map { Form::Factory::Control::Choice->new($_) } qw( PST MST CST EST )
],
},
features => {
match_available_choices => 1,
},
);
Verifies that the value set for the control matches one of the available choices.
Verifies that the control does the Form::Factory::Control::Role::AvailableChoices.
Verifies that the value or values set match one or more of the available values.
Andrew Sterling Hanenkamp <hanenkamp@cpan.org>
Copyright 2009 Qubling Software LLC.
This library is free software. You can redistribute it and/or modify it under the same terms as Perl itself.
| Form-Factory documentation | Contained in the Form-Factory distribution. |
package Form::Factory::Feature::Control::MatchAvailableChoices; BEGIN { $Form::Factory::Feature::Control::MatchAvailableChoices::VERSION = '0.020'; } use Moose; with qw( Form::Factory::Feature Form::Factory::Feature::Role::Check Form::Factory::Feature::Role::Control Form::Factory::Feature::Role::CustomControlMessage ); use Carp ();
sub check_control { my ($self, $control) = @_; Carp::croak("the match_available_options feature only works for controls that have available choices, not $control") unless $control->does('Form::Factory::Control::Role::AvailableChoices'); }
sub check { my $self = shift; my $control = $self->control; my %available_values = map { $_->value => 1 } @{ $self->control->available_choices }; # Deal with list valued controls if ($control->does('Form::Factory::Control::Role::ListValue')) { my $values = $control->current_values; VALUE: for my $value (@$values) { unless ($available_values{ $value }) { $self->control_error('one of the values given for %s is not in the list of available choices'); $self->result->is_valid(0); last VALUE; } } } # Deal with scalar valued controls else { my $value = $control->current_value; unless ($available_values{ $value }) { $self->control_error('the given value for %s is not one of the available choices'); $self->is_valid(0); } } # If not already validated $self->result->is_valid(1) unless $self->result->is_validated; }
1;