Skip to content
This repository
  • 3 commits
  • 5 files changed
  • 0 comments
  • 1 contributor
7 Changes
... ... @@ -1,3 +1,4 @@
  1 +0.40011 Tue Jun 5, 2012
1 2 Remove automatic building of field results. If you have field tests, you
2 3 need to add $field->build_result after creating field with 'new'.
3 4 Possible memory cycle if result is accessed when not built.
@@ -5,10 +6,14 @@
5 6 Add Bulgarian message file (dpetrov)
6 7 Bootstrap input_append/prepend: no linefeeds between input
7 8 Add input_append_button tag to Bootstrap wrapper
  9 + Correct camelcase for widgets in two fields
  10 + Add 'value_when_empty' for multiple select
  11 + Add SelectCSV multiple field
  12 + Change Select to use sort_options_method for sorting
8 13
9 14 0.40010 Sun May 20, 2012
10 15 Add 'when' clause to apply actions
11   - Fix memory leak on fields with defaults due to missing my causing
  16 + Fix memory leak on fields with defaults due to missing 'my' causing
12 17 $self to be closed over so that RAM was leaked if forms were constructed
13 18 but never processed. (in default_<field_name> & validate_<field_name>
14 19 methods)
2  dist.ini
@@ -7,7 +7,7 @@ license = Perl_5
7 7 copyright_holder = Gerda Shank
8 8 copyright_year = 2012
9 9
10   -version = 0.40010
  10 +version = 0.40011
11 11
12 12 [@Git]
13 13 tag_format = %v
2  lib/HTML/FormHandler.pm
@@ -25,7 +25,7 @@ use Data::Clone;
25 25 use 5.008;
26 26
27 27 # always use 5 digits after decimal because of toolchain issues
28   -our $VERSION = '0.40010';
  28 +our $VERSION = '0.40011';
29 29
30 30 =head1 SYNOPSIS
31 31
23 lib/HTML/FormHandler/Field/Multiple.pm
... ... @@ -1,14 +1,23 @@
1 1 package HTML::FormHandler::Field::Multiple;
2 2 # ABSTRACT: multiple select list
3   -
4 3 use Moose;
5 4 extends 'HTML::FormHandler::Field::Select';
6 5 our $VERSION = '0.01';
7 6
  7 +=head1 DESCRIPTION
  8 +
  9 +This is a convenience field that inherits from the Select field and
  10 +pre-sets some attributes. It sets the 'multiple' flag,
  11 +sets the 'size' attribute to 5, and sets the 'sort_options_method' to
  12 +move the currently selected options to the top of the options list.
  13 +
  14 +=cut
  15 +
8 16 has '+multiple' => ( default => 1 );
9 17 has '+size' => ( default => 5 );
  18 +has '+sort_options_method' => ( default => sub { \&default_sort_options } );
10 19
11   -sub sort_options {
  20 +sub default_sort_options {
12 21 my ( $self, $options ) = @_;
13 22
14 23 return $options unless scalar @$options && defined $self->value;
@@ -22,16 +31,6 @@ sub sort_options {
22 31 return \@out;
23 32 }
24 33
25   -=head1 DESCRIPTION
26   -
27   -This inherits from the Select field,
28   -and sets the "multiple" flag true to accept multiple options.
29   -
30   -The currently selected items will be put at the top of the list.
31   -Widget type is 'select'.
32   -
33   -=cut
34   -
35 34 __PACKAGE__->meta->make_immutable;
36 35 use namespace::autoclean;
37 36 1;
14 lib/HTML/FormHandler/Field/Select.pm
@@ -354,6 +354,15 @@ has 'options_method' => (
354 354 get_options => 'execute_method',
355 355 },
356 356 );
  357 +has 'sort_options_method' => (
  358 + traits => ['Code'],
  359 + is => 'rw',
  360 + isa => 'CodeRef',
  361 + predicate => 'has_sort_options_method',
  362 + handles => {
  363 + sort_options => 'execute_method',
  364 + },
  365 +);
357 366
358 367 has 'set_options' => ( isa => 'Str', is => 'ro');
359 368 sub _set_options_meth {
@@ -567,7 +576,8 @@ sub _load_options {
567 576 push @{$opts}, { value => shift @options, label => shift @options } while @options;
568 577 }
569 578 if ($opts) {
570   - my $opts = $self->sort_options($opts); # allow sorting options
  579 + # sort options if sort method exists
  580 + $opts = $self->sort_options($opts) if $self->has_sort_options_method;
571 581 $self->options($opts);
572 582 }
573 583 }
@@ -593,8 +603,6 @@ sub default_from_options {
593 603 }
594 604 }
595 605
596   -sub sort_options { shift; return shift; }
597   -
598 606 before 'value' => sub {
599 607 my $self = shift;
600 608

No commit comments for this range

Something went wrong with that request. Please try again.