新手提醒,我真的很喜欢 perl Catalyst,但是,我用谷歌搜索并找不到国家 - 城市动态选择的解决方案。当我从下拉列表中选择一个国家/地区时,我希望这些城市仅更改为该国家/地区的城市。我如何在 Perl、Catalyst 中使用 HTML::FormHandler 实现这一点。
PS数据来自mysql db,具有一对多关系
has_field 'city_id' => (
label => 'City',
type => 'Select',
empty_select => 'Choose city',
required => 1,
required_message => 'Please enter city.',
);
has_field 'country_code' => (
label => 'Country',
type => 'Select',
empty_select => 'Choose country',
required => 1,
required_message => 'Please enter your country.',
);
has_field 'submit' => (
type => 'Submit',
value => 'Save',
element_class => ['btn']
);
sub options_country_code {
my $self = shift;
return unless $self->schema;
my @countries = $self->schema->resultset('Country')->all;
my @options = map { { value => $_->country_code, label => $_->country_name } } @countries;
unshift @options, { value => 0, label => 'Choose Country' };
return @options;
}
__PACKAGE__->meta->make_immutable;
1;