1 package Reaction::UI::ViewPort::Field::ChooseMany;
5 class ChooseMany is 'Reaction::UI::ViewPort::Field::ChooseOne', which {
7 #has '+layout' => (default => 'dual_select_group');
8 has '+value' => (isa => 'ArrayRef');
10 my $listify = sub { # quick utility function, $listify->($arg)
11 return (defined($_[0])
12 ? (ref($_[0]) eq 'ARRAY'
13 ? $_[0] # \@arr => \@arr
14 : [$_[0]]) # $scalar => [$scalar]
22 my $value = $listify->(shift);
24 $_ = $self->str_to_ident($_) for @$value;
25 my $checked = $self->attribute->check_valid_value($self->action, $value);
26 # i.e. fail if any of the values fail
27 confess "Not a valid set of values"
28 if (@$checked < @$value || grep { !defined($_) } @$checked);
32 $orig->($self, $value);
38 override build_value => sub {
42 implements is_current_value => as {
43 my ($self, $check_value) = @_;
44 my @our_values = @{$self->value||[]};
45 $check_value = $self->obj_to_str($check_value) if ref($check_value);
46 return grep { $self->obj_to_str($_) eq $check_value } @our_values;
49 implements current_value_choices => as {
51 my @all = grep { $self->is_current_value($_->{value}) } @{$self->value_choices};
55 implements available_value_choices => as {
57 my @all = grep { !$self->is_current_value($_->{value}) } @{$self->value_choices};
61 around handle_events => sub {
63 my ($self, $events) = @_;
64 my $ev_value = $listify->($events->{value});
65 if (delete $events->{add_all_values}) {
66 $events->{value} = [map {$self->obj_to_str($_)} @{$self->valid_values}];
67 } elsif (exists $events->{add_values} && delete $events->{do_add_values}) {
68 my $add = $listify->(delete $events->{add_values});
69 $events->{value} = [ @{$ev_value}, @$add ];
70 } elsif (delete $events->{remove_all_values}) {
71 $events->{value} = [];
72 }elsif (exists $events->{remove_values} && delete $events->{do_remove_values}) {
73 my $remove = $listify->(delete $events->{remove_values});
74 my %r = map { ($_ => 1) } @$remove;
75 $events->{value} = [ grep { !$r{$_} } @{$ev_value} ];
86 Reaction::UI::ViewPort::Field::ChooseMany
92 =head2 is_current_value
96 =head2 available_values
98 =head2 available_value_names
102 =head2 L<Reaction::UI::ViewPort::Field>
106 See L<Reaction::Class> for authors.
110 See L<Reaction::Class> for the license.