1 package Reaction::UI::ViewPort::Field::Mutable::ChooseMany;
6 return [] unless defined $_[0];
7 return ref $_[0] eq 'ARRAY' ? $_[0] : [$_[0]];
10 class ChooseMany is 'Reaction::UI::ViewPort::Field', which {
12 has '+value' => (isa => 'ArrayRef');
14 does 'Reaction::UI::ViewPort::Field::Role::Mutable';
15 does 'Reaction::UI::ViewPort::Field::Role::Choices';
20 return $orig->($self) unless @_;
21 my $value = $listify->(shift);
22 $_ = $self->str_to_ident($_) for @$value;
23 my $checked = $self->attribute->check_valid_value($self->action, $value);
24 # i.e. fail if any of the values fail
25 confess "Not a valid set of values"
26 if (@$checked < @$value || grep { !defined($_) } @$checked);
27 $orig->($self, $checked);
31 override _build_value => sub {
35 implements is_current_value => as {
36 my ($self, $check_value) = @_;
37 my @our_values = @{$self->value||[]};
38 $check_value = $self->obj_to_str($check_value) if ref($check_value);
39 return grep { $self->obj_to_str($_) eq $check_value } @our_values;
42 implements current_value_choices => as {
44 my @all = grep { $self->is_current_value($_->{value}) } @{$self->value_choices};
48 implements available_value_choices => as {
50 my @all = grep { !$self->is_current_value($_->{value}) } @{$self->value_choices};
54 around handle_events => sub {
56 my ($self, $events) = @_;
57 my $ev_value = $listify->($events->{value});
58 if (delete $events->{add_all_values}) {
59 $events->{value} = [map {$self->obj_to_str($_)} @{$self->valid_values}];
60 } elsif (exists $events->{add_values} && delete $events->{do_add_values}) {
61 my $add = $listify->(delete $events->{add_values});
62 $events->{value} = [ @{$ev_value}, @$add ];
63 } elsif (delete $events->{remove_all_values}) {
64 $events->{value} = [];
65 }elsif (exists $events->{remove_values} && delete $events->{do_remove_values}) {
66 my $remove = $listify->(delete $events->{remove_values});
67 my %r = map { ($_ => 1) } @$remove;
68 $events->{value} = [ grep { !$r{$_} } @{$ev_value} ];
79 Reaction::UI::ViewPort::Field::ChooseMany
85 =head2 is_current_value
89 =head2 available_values
91 =head2 available_value_names
95 =head2 L<Reaction::UI::ViewPort::Field>
99 See L<Reaction::Class> for authors.
103 See L<Reaction::Class> for the license.