| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
use Test::More; |
| 4 |
|
| 5 |
# Test using the 'include' attribute on a compound field |
| 6 |
# to limit the fields that are built. |
| 7 |
# alternative to active/inactive. Created for a situation |
| 8 |
# in which there are a very large number of fields in a |
| 9 |
# field/role and you don't want the overhead of building them |
| 10 |
# and then setting them activie/inactive. |
| 11 |
{ |
| 12 |
package Test::FooField; |
| 13 |
use HTML::FormHandler::Moose; |
| 14 |
extends 'HTML::FormHandler::Field::Compound'; |
| 15 |
|
| 16 |
has_field 'foo'; |
| 17 |
has_field 'bar'; |
| 18 |
has_field 'box'; |
| 19 |
has_field 'mix'; |
| 20 |
has_field 'nix'; |
| 21 |
|
| 22 |
} |
| 23 |
|
| 24 |
my $field = Test::FooField->new( name => 'muddly' ); |
| 25 |
ok( $field ); |
| 26 |
|
| 27 |
{ |
| 28 |
package Test::Form; |
| 29 |
use HTML::FormHandler::Moose; |
| 30 |
extends 'HTML::FormHandler'; |
| 31 |
|
| 32 |
has_field 'fiddly'; |
| 33 |
has_field 'muddly' => ( type => '+Test::FooField', include => ['foo', 'mix', 'nix'] ); |
| 34 |
# no subfields. kinda weird... |
| 35 |
has_field 'middly' => ( type => '+Test::FooField', include => [ 'empty' ] ); |
| 36 |
} |
| 37 |
|
| 38 |
my $form = Test::Form->new; |
| 39 |
ok( $form ); |
| 40 |
is( $form->field('muddly')->num_fields, 3, 'right number of fields' ); |
| 41 |
is( $form->field('middly')->num_fields, 0, 'right number of fields' ); |
| 42 |
|
| 43 |
done_testing; |