Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Forms::Address;
- use HTML::FormHandler::Moose;
- extends 'HTML::FormHandler';
- with 'HTML::FormHandler::TraitFor::Model::DBIC';
- has_field 'addr_country' => (
- type => 'Select',
- label => 'Country',
- order => 1,
- empty_select => '-- Choose a Country --',
- options => [
- { value => 'AU', label => 'AU' },
- { value => 'NZ', label => 'NZ' },
- ],
- );
- has_field 'addr_state' => (
- type => 'Select',
- label => 'State',
- order => 2,
- empty_select => '-- Select State --',
- options_method => \&options_addr_state,
- );
- sub options_addr_state {
- my $self = shift;
- return unless $self->form->schema;
- my $country = $self->form->field('addr_country');
- my $country_code = $country->value;
- my @values = $self->form->schema->resultset('States')->search(
- { country_code => $country_code, state => { '!=' => '' } },
- {
- select => [{ distinct => ['state'] }],
- as => ['state'],
- order_by => 'state',
- }
- )->get_column('state')->all;
- return [map { value=>$_, label=>$_ } @values];
- } ## end sub options_addr_state
- __PACKAGE__->meta->make_immutable;
- 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement