1package BookDB::Form::User; 2 3use HTML::FormHandler::Moose; 4extends 'HTML::FormHandler::Model::DBIC'; 5use DateTime; 6 7has '+item_class' => ( default => 'User'); 8 9has_field 'user_name'; 10has_field 'fav_cat' => ( label => 'Category' ); 11has_field 'fav_book' => ( label => 'Favorite Book' ); 12has_field 'occupation'; 13has_field 'country' => ( type => 'Select' ); 14has_field 'license' => ( type => 'Select' ); 15has_field 'opt_in' => ( type => 'Checkbox' ); 16has_field 'birthdate' => ( type => 'DateTime' ); 17has_field 'birthdate.year' => ( type => 'Text', ); 18has_field 'birthdate.month' => ( type => 'Text', ); 19has_field 'birthdate.day' => ( type => 'Text', ); 20 21has_field 'employers' => ( type => 'Repeatable' ); 22has_field 'employers.employer_id' => ( type => 'PrimaryKey' ); 23has_field 'employers.name'; 24has_field 'employers.category'; 25has_field 'employers.country'; 26 27has_field 'addresses' => ( type => 'Repeatable' ); 28has_field 'addresses.address_id' => ( type => 'PrimaryKey' ); 29has_field 'addresses.street'; 30has_field 'addresses.city'; 31has_field 'addresses.country' => ( type => 'Select' ); 32 33sub options_opt_in 34{ 35 return ( 36 0 => 'Send no emails', 37 1 => 'Send related emails' 38 ); 39} 40 41sub init_value_license 42{ 43 my ( $self, $field, $item ) = @_; 44 45 return 0 unless $item && $item->license_id && $item->license_id != 0; 46 return $item->license_id; 47 48} 49sub validate_occupation 50{ 51 my ( $self, $field ) = @_; 52 if ( $field->value eq 'layabout' ) 53 { 54 $field->add_error('No layabouts allowed'); 55 } 56} 57 58no HTML::FormHandler::Moose; 591; 60