1package BookDB::Form::Book2PK; 2use HTML::FormHandler::Moose; 3extends 'HTML::FormHandler::Model::DBIC'; 4 5with 'HTML::FormHandler::Widget::Theme::Bootstrap'; 6 7=head1 NAME 8 9Form object for the Book Controller 10 11=head1 SYNOPSIS 12 13Form used for book/add and book/edit actions 14 15=head1 DESCRIPTION 16 17Catalyst Form. 18 19=cut 20 21has '+item_class' => ( default => 'Book2PK' ); 22 23has_field 'title' => ( 24 type => 'Text', 25 required => 1, 26 required_message => 'A book must have a title.', 27 label => 'Title', 28); 29 30has_field 'publisher' => ( 31 type => 'Text', 32 label => 'Publisher', 33); 34 35# has_many relationship pointing to mapping table 36has_field 'isbn' => ( 37 type => 'Text', 38 label => 'ISBN', 39 unique => 1, 40 required => 1, 41); 42has_field 'year' => ( 43 type => 'Integer', 44 range_start => '1900', 45 range_end => '2020', 46 label => 'Year', 47 required => 1, 48); 49has_field 'pages' => ( 50 type => 'Integer', 51 label => 'Pages', 52); 53 54has_field submit => ( type => 'Submit', value => 'Update', element_class => ['btn'] ); 55 56sub validate_year { 57 my ( $self, $field ) = @_; 58 $field->add_error('Invalid year') 59 if ( ( $field->value > 3000 ) || ( $field->value < 1600 ) ); 60} 61 62=head1 AUTHOR 63 64Gerda Shank 65 66=head1 LICENSE AND COPYRIGHT 67 68This module is free software; you can redistribute it and/or 69modify it under the same terms as Perl itself. See L<perlartistic>. 70 71=cut 72 73__PACKAGE__->meta->make_immutable; 74no HTML::FormHandler::Moose; 751; 76