Skip to content

Commit

Permalink
Merge pull request gshank#4 from boghead/master
Browse files Browse the repository at this point in the history
Changed author.t to reproduce a repeatable fields bug
  • Loading branch information
gshank committed Dec 1, 2011
2 parents 7e835f5 + 9ff5bfb commit 7bac8c3
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 7 deletions.
3 changes: 3 additions & 0 deletions t/author.t
Expand Up @@ -18,6 +18,9 @@ $form->process( item => $author, params => {});
my @options = $form->field('books.0.genres')->options;
is(scalar @options, 6, 'got right number of genre options' );

my @formats = $form->field('books.0.format')->options;
is(scalar @formats, 6, 'got right number of format options');

my $fif = $form->fif;

done_testing;
8 changes: 1 addition & 7 deletions t/lib/BookDB/Form/Author.pm
Expand Up @@ -10,13 +10,7 @@ has_field 'first_name' => ( type => 'Text', required => 1 );
has_field 'country' => ( type => 'Text' );
has_field 'birthdate' => ( type => 'DateTime' );
has_field 'books' => ( type => 'Repeatable' );
has_field 'books.id' => ( type => 'PrimaryKey' );
has_field 'books.title';
has_field 'books.publisher';
has_field 'books.year';
has_field 'books.genres' => ( type => 'Multiple', label_column => 'name' );
has_field 'books.format' => ( type => 'Select' );

has_field 'books.contains' => ( type => '+BookDB::Form::Field::Book' );

no HTML::FormHandler::Moose;
1;
70 changes: 70 additions & 0 deletions t/lib/BookDB/Form/Field/Book.pm
@@ -0,0 +1,70 @@
package BookDB::Form::Field::Book;

use HTML::FormHandler::Moose;
extends 'HTML::FormHandler::Field::Compound';

has_field 'id' => (
type => 'PrimaryKey',
);

has_field 'title' => (
type => 'Text',
required => 1,
required_message => 'A book must have a title.',
label => 'Title',
);
has_field 'authors' => (
type => 'Multiple',
label => 'Authors',
);

has_field 'user_updated' => (
type => 'Boolean'
);

# has_many relationship pointing to mapping table
has_field 'genres' => (
type => 'Multiple',
label => 'Genres',
label_column => 'name',
);
has_field 'isbn' => (
type => 'Text',
label => 'ISBN',
unique => 1,
);
has_field 'publisher' => (
type => 'Text',
label => 'Publisher',
);
has_field 'format' => (
type => 'Select',
label => 'Format',
);
has_field 'year' => (
type => 'Integer',
range_start => '1900',
range_end => '2020',
label => 'Year',
);
has_field 'pages' => (
type => 'Integer',
label => 'Pages',
);
has_field 'comment' => (
type => 'Text',
);

has_field submit => ( type => 'Submit', value => 'Update' );

sub validate {
my $self = shift;

my $year_field = $self->field('year');
$year_field->add_error('Invalid year')
if ( ( $year_field->value > 3000 ) || ( $year_field->value < 1600 ) );
}

__PACKAGE__->meta->make_immutable;
no HTML::FormHandler::Moose;
1;

0 comments on commit 7bac8c3

Please sign in to comment.