| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
use Test::More; |
| 4 |
|
| 5 |
{ |
| 6 |
package Test::Form::Field::Phone; |
| 7 |
use HTML::FormHandler::Moose; |
| 8 |
extends 'HTML::FormHandler::Field::Compound'; |
| 9 |
|
| 10 |
has_field 'id' => ( type => 'PrimaryKey' ); |
| 11 |
has_field 'number'; |
| 12 |
has_field 'comment'; |
| 13 |
} |
| 14 |
|
| 15 |
{ |
| 16 |
package Test::Form::Client; |
| 17 |
use HTML::FormHandler::Moose; |
| 18 |
extends 'HTML::FormHandler'; |
| 19 |
|
| 20 |
has_field 'name' => (type => 'Text'); |
| 21 |
has_field 'comment'; |
| 22 |
has_field 'phones' => ( type => 'Repeatable' ); |
| 23 |
has_field 'phones.contains' => ( type => '+Test::Form::Field::Phone'); |
| 24 |
} |
| 25 |
|
| 26 |
my $form = Test::Form::Client->new; |
| 27 |
$form->process(params=>{ |
| 28 |
name => 'test client', |
| 29 |
phones => [ |
| 30 |
{id=> 0, number => '123', comment => 'phone comment'} |
| 31 |
] |
| 32 |
}); |
| 33 |
ok( $form, 'form built' ); |
| 34 |
is($form->field('phones.0.number')->value, '123', 'phone number is correct'); |
| 35 |
is($form->field('phones.0.comment')->id, 'phones.0.comment', 'phone comment id is correct'); |
| 36 |
|
| 37 |
done_testing; |
| 38 |
|