Index: t/constraints/autoset.t =================================================================== --- t/constraints/autoset.t (revision 304) +++ t/constraints/autoset.t (working copy) @@ -1,12 +1,15 @@ use strict; use warnings; -use Test::More tests => 2; +use Test::More tests => 4; use HTML::FormFu; my $form = HTML::FormFu->new; +############################################################################## +### Autoset with multiple values +############################################################################## $form->element('Select') ->name('foo') ->values([qw/ one two three /]) @@ -29,3 +32,30 @@ ok( $form->has_errors('foo') ); } + +############################################################################## +### Autoset with a single value +############################################################################## +$form->element('Select') + ->name('bar') + ->values([qw/ one /]) + ->constraint('AutoSet'); + +# Valid +{ + $form->process( { + bar => 'one', + } ); + + ok( $form->valid('bar') ); +} + +# Invalid +{ + $form->process( { + bar => 'yes', + } ); + + ok( $form->has_errors('bar') ); +} + Index: lib/HTML/FormFu/Constraint/AutoSet.pm =================================================================== --- lib/HTML/FormFu/Constraint/AutoSet.pm (revision 304) +++ lib/HTML/FormFu/Constraint/AutoSet.pm (working copy) @@ -8,7 +8,8 @@ sub process { my $self = shift; - $self->set( map { $_->{value} } @{ $self->parent->_options } ); + my @set = map { $_->{value} } @{ $self->parent->_options }; + $self->set( \@set ); return $self->next::method(@_); }