| 1 |
package HTML::FormHandler::Field::Multiple; |
| 2 |
# ABSTRACT: multiple select list |
| 3 |
$HTML::FormHandler::Field::Multiple::VERSION = '0.410002'; |
| 4 |
use Moose; |
| 5 |
extends 'HTML::FormHandler::Field::Select'; |
| 6 |
|
| 7 |
|
| 8 |
has '+multiple' => ( default => 1 ); |
| 9 |
has '+size' => ( default => 5 ); |
| 10 |
has '+sort_options_method' => ( default => sub { \&default_sort_options } ); |
| 11 |
|
| 12 |
sub default_sort_options { |
| 13 |
my ( $self, $options ) = @_; |
| 14 |
|
| 15 |
return $options unless scalar @$options && defined $self->value; |
| 16 |
my $value = $self->deflate($self->value); |
| 17 |
return $options unless scalar @$value; |
| 18 |
# This places the currently selected options at the top of the list |
| 19 |
# Makes the drop down lists a bit nicer |
| 20 |
my %selected = map { $_ => 1 } @$value; |
| 21 |
my @out = grep { $selected{ $_->{value} } } @$options; |
| 22 |
push @out, grep { !$selected{ $_->{value} } } @$options; |
| 23 |
return \@out; |
| 24 |
} |
| 25 |
|
| 26 |
__PACKAGE__->meta->make_immutable; |
| 27 |
use namespace::autoclean; |
| 28 |
1; |
| 29 |
|
| 30 |
__END__ |
| 31 |
|
| 32 |
=pod |
| 33 |
|
| 34 |
=encoding UTF-8 |
| 35 |
|
| 36 |
=head1 NAME |
| 37 |
|
| 38 |
HTML::FormHandler::Field::Multiple - multiple select list |
| 39 |
|
| 40 |
=head1 VERSION |
| 41 |
|
| 42 |
version 0.410002 |
| 43 |
|
| 44 |
=head1 DESCRIPTION |
| 45 |
|
| 46 |
This is a convenience field that inherits from the Select field and |
| 47 |
pre-sets some attributes. It sets the 'multiple' flag, |
| 48 |
sets the 'size' attribute to 5, and sets the 'sort_options_method' to |
| 49 |
move the currently selected options to the top of the options list. |
| 50 |
|
| 51 |
=head1 AUTHOR |
| 52 |
|
| 53 |
FormHandler Contributors - see HTML::FormHandler |
| 54 |
|
| 55 |
=head1 COPYRIGHT AND LICENSE |
| 56 |
|
| 57 |
This software is copyright (c) 2017 by Gerda Shank. |
| 58 |
|
| 59 |
This is free software; you can redistribute it and/or modify it under |
| 60 |
the same terms as the Perl 5 programming language system itself. |
| 61 |
|
| 62 |
=cut |