1package BookDB::Form::Book;
2
3use HTML::FormHandler::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' );
21has '+widget_name_space' => ( default => sub { ['BookDB::Form::Widget'] } );
22has '+widget_wrapper'    => ( default => 'Para' );
23
24has_field 'title' => (
25    type             => 'Text',
26    required         => 1,
27    required_message => 'A book must have a title.',
28    label            => 'Title',
29    order           => '1',
30);
31has_field 'authors' => (
32    type  => 'Multiple',
33    label => 'Authors',
34    label_column => 'full_name',
35    order => '2',
36);
37
38has_field 'user_updated' => (
39    type => 'Boolean'
40);
41
42# has_many relationship pointing to mapping table
43has_field 'genres' => (
44    type         => 'Multiple',
45    label        => 'Genres',
46    label_column => 'name',
47    order        => '3',
48);
49has_field 'isbn' => (
50    type   => 'Text',
51    label  => 'ISBN',
52    order  => '5',
53    unique => 1,
54);
55has_field 'publisher' => (
56    type  => 'Text',
57    label => 'Publisher',
58    order => '4',
59);
60has_field 'format' => (
61    type  => 'Select',
62    label => 'Format',
63    order => '6',
64);
65has_field 'year' => (
66    type        => 'Integer',
67    range_start => '1900',
68    range_end   => '2020',
69    label       => 'Year',
70    order       => '7',
71);
72has_field 'pages' => (
73    type  => 'Integer',
74    label => 'Pages',
75    order => '8',
76);
77has_field 'comment' => (
78    type  => 'Text',
79    order => 9,
80);
81
82has_field 'borrower' => (
83    type => 'Select',
84    label_column => 'name_email',
85);
86
87has_field submit => ( type => 'Submit', value => 'Update' );
88
89sub validate_year {
90    my ( $self, $field ) = @_;
91    $field->add_error('Invalid year')
92      if ( ( $field->value > 3000 ) || ( $field->value < 1600 ) );
93}
94
95=head1 AUTHOR
96
97Gerda Shank
98
99=head1 LICENSE AND COPYRIGHT
100
101This module is free software; you can redistribute it and/or
102modify it under the same terms as Perl itself. See L<perlartistic>.
103
104=cut
105
106__PACKAGE__->meta->make_immutable;
107no HTML::FormHandler::Moose;
1081;
109