1package BookDB::Form::BookM2M; 2 3use Moose; 4extends 'HTML::FormHandler::Model::DBIC'; 5 6=head1 NAME 7 8Form object for the Book Controller 9 10=head1 SYNOPSIS 11 12Form used for book/add and book/edit actions 13 14=head1 DESCRIPTION 15 16Catalyst Form. 17 18=cut 19 20has '+item_class' => ( default => 'Book' ); 21 22sub field_list { 23 [ 24 title => { 25 type => 'Text', 26 required => 1, 27 required_message => 'A book must have a title.', 28 label => 'Title', 29 order => '1', 30 }, 31 author => { 32 type => 'Text', 33 label => 'Author:', 34 order => '2', 35 }, 36 37 # has_many relationship pointing to mapping table 38 genres => { 39 type => 'Multiple', 40 label => 'Genres:', 41 label_column => 'name', 42 order => '3', 43 }, 44 isbn => { 45 type => 'Text', 46 label => 'ISBN:', 47 order => '5', 48 unique => 1, 49 }, 50 publisher => { 51 type => 'Text', 52 label => 'Publisher:', 53 order => '4', 54 }, 55 format => { 56 type => 'Select', 57 label => 'Format:', 58 order => '6', 59 }, 60 year => { 61 type => 'Integer', 62 range_start => '1900', 63 range_end => '2020', 64 label => 'Year:', 65 order => '7', 66 }, 67 pages => { 68 type => 'Integer', 69 label => 'Pages:', 70 order => '8', 71 }, 72 comment => { 73 type => 'Text', 74 order => 9, 75 }, 76 ]; 77} 78 79sub validate_year { 80 my ( $self, $field ) = @_; 81 $field->add_error('Invalid year') 82 if ( ( $field->value > 3000 ) || ( $field->value < 1600 ) ); 83} 84 85=head1 AUTHOR 86 87Gerda Shank 88 89=head1 LICENSE AND COPYRIGHT 90 91This module is free software; you can redistribute it and/or 92modify it under the same terms as Perl itself. See L<perlartistic>. 93 94=cut 95 961; 97