| 1 |
package HTML::FormHandler::Field::SelectCSV; |
| 2 |
# ABSTRACT: Multiple select field from CSV value |
| 3 |
$HTML::FormHandler::Field::SelectCSV::VERSION = '0.410002'; |
| 4 |
use HTML::FormHandler::Moose; |
| 5 |
extends 'HTML::FormHandler::Field::Select'; |
| 6 |
|
| 7 |
|
| 8 |
has '+inflate_default_method' => ( default => sub { \&selectcsv_inflate_default } ); |
| 9 |
has '+deflate_value_method' => ( default => sub { \&selectcsv_deflate_value } ); |
| 10 |
has '+multiple' => ( default => 1 ); |
| 11 |
sub build_value_when_empty { undef } |
| 12 |
|
| 13 |
sub selectcsv_inflate_default { |
| 14 |
my ( $self, $value ) = @_; |
| 15 |
if( defined $value ) { |
| 16 |
my @values = split (/,/, $value); |
| 17 |
return @values; |
| 18 |
} |
| 19 |
return; |
| 20 |
} |
| 21 |
|
| 22 |
sub selectcsv_deflate_value { |
| 23 |
my ( $self, $value ) = @_; |
| 24 |
if ( defined $value ) { |
| 25 |
my $str = join( ',', sort @$value ); |
| 26 |
return $str; |
| 27 |
} |
| 28 |
return; |
| 29 |
} |
| 30 |
|
| 31 |
sub fif { |
| 32 |
my $self = shift; |
| 33 |
my $fif = $self->next::method; |
| 34 |
$fif = [] if $fif eq ''; |
| 35 |
return $fif; |
| 36 |
} |
| 37 |
|
| 38 |
1; |
| 39 |
|
| 40 |
__END__ |
| 41 |
|
| 42 |
=pod |
| 43 |
|
| 44 |
=encoding UTF-8 |
| 45 |
|
| 46 |
=head1 NAME |
| 47 |
|
| 48 |
HTML::FormHandler::Field::SelectCSV - Multiple select field from CSV value |
| 49 |
|
| 50 |
=head1 VERSION |
| 51 |
|
| 52 |
version 0.410002 |
| 53 |
|
| 54 |
=head1 SYNOPSIS |
| 55 |
|
| 56 |
A multiple select field for comma-separated values in the database. |
| 57 |
It expects database values like: '1,5,7'. The string will be inflated |
| 58 |
into an arrayref for validation and form filling, and will be deflated |
| 59 |
into a comma-separated string in the output value. |
| 60 |
|
| 61 |
This field is useful for MySQL 'set' columns. |
| 62 |
|
| 63 |
=head1 NAME |
| 64 |
|
| 65 |
HTML::FormHandler::Field::SelectCSV |
| 66 |
|
| 67 |
=head1 AUTHOR |
| 68 |
|
| 69 |
FormHandler Contributors - see HTML::FormHandler |
| 70 |
|
| 71 |
=head1 COPYRIGHT AND LICENSE |
| 72 |
|
| 73 |
This software is copyright (c) 2017 by Gerda Shank. |
| 74 |
|
| 75 |
This is free software; you can redistribute it and/or modify it under |
| 76 |
the same terms as the Perl 5 programming language system itself. |
| 77 |
|
| 78 |
=cut |