if ($attr_opts{required}) {
$attr_opts{lazy} = 1;
- $attr_opts{default} = $from_attr->has_default ? $from_attr->default :
- sub{confess("${attr_name} must be provided before calling reader")};
+ $attr_opts{default} = $from_attr->has_default ?
+ $from_attr->default : sub{};
}
#test for relationships
implements _build_value_names => as {
my $self = shift;
- my @all = @{ $self->value || []};
my $meth = $self->value_map_method;
- my @names = map { blessed($_) ? $_->$meth : $_ } @all;
+ my @names = map { blessed($_) ? $_->$meth : $_ } @{ $self->value };
return [ sort @names ];
};
+ implements _empty_value => as { [] };
};
1;
class Boolean, is Field, which {
has '+value' => (isa => 'Bool');
+
+ implements _empty_value => as { undef };
};
1;
}
};
- override _build_value => sub {
- return super() || [];
- };
+ implements _empty_value => as { [] };
implements is_current_value => as {
my ($self, $check_value) = @_;
}
};
+ implements _empty_value => as { undef };
+
implements _build_valid_values => as {
my $self = shift;
return [ $self->attribute->all_valid_values($self->action) ];
#XXX
override _build_value => sub {
- return [super()->members];
+ my $collection = super();
+ return blessed($collection) ? [$collection->members] : $collection;
};
};
package Reaction::UI::ViewPort::Field::DateTime;
+use Scalar::Util 'blessed';
use Reaction::Class;
use Reaction::Types::DateTime;
use aliased 'Reaction::UI::ViewPort::Field';
#<mst> it's because if value's calculated
#<mst> it needs to be possible to clear it
#<mst> eval { $self->value } ... is probably the best solution atm
- my $value = eval { $self->value };
- return '' unless $self->has_value;
+ my $value = $self->value;
+ return '' unless blessed $value;
my $format = $self->value_string_default_format;
- return $value->strftime($format) if $value;
- return '';
+ return $value->strftime($format);
};
+ implements _empty_value => as { undef };
+
};
1;
class HiddenArray is 'Reaction::UI::ViewPort::Field', which {
has '+value' => (isa => 'ArrayRef');
-
+
around value => sub {
my $orig = shift;
my $self = shift;
if (@_) {
+ #this hsould be done with coercions
$orig->($self, (ref $_[0] eq 'ARRAY' ? $_[0] : [ $_[0] ]));
$self->sync_to_action;
} else {
}
};
+ implements _empty_value => as { [] };
};
-1;
+1;
=head1 NAME
use Reaction::Class;
my $listify = sub{
- return [] unless defined $_[0];
+ return [] unless defined($_[0]);
return ref $_[0] eq 'ARRAY' ? $_[0] : [$_[0]];
};
around handle_events => sub {
my $orig = shift;
my ($self, $events) = @_;
+ $events->{value} = [] if $events->{no_current_value};
my $ev_value = $listify->($events->{value});
if (delete $events->{add_all_values}) {
$events->{value} = [map {$self->obj_to_str($_)} @{$self->valid_values}];
my %r = map { ($_ => 1) } @$remove;
$events->{value} = [ grep { !$r{$_} } @{$ev_value} ];
}
+
return $orig->(@_);
};
return blessed($value) ? $value->$meth : $value;
};
+ implements _empty_value => as { undef };
+
};
1;
my ($self) = @_;
return unless $self->needs_sync && $self->has_value;
my $attr = $self->attribute;
+ my $writer = $attr->get_write_method;
+ confess "No writer for attribute" unless defined($writer);
+
+ my $value = $self->value;
if (my $tc = $attr->type_constraint) {
- my $value = $self->value;
$value = $tc->coercion->coerce($value) if ($tc->has_coercion);
- my $error = $tc->validate($self->value); # should we be checking against $value?
+ #my $error = $tc->validate($self->value); # should we be checking against $value?
+ my $error = $tc->validate($value);
if (defined $error) {
$self->message($error);
return;
}
}
- my $writer = $attr->get_write_method;
- confess "No writer for attribute" unless defined($writer);
- my $value = $self->value;
- $self->model->$writer($self->value); #should we be passing $value ?
+ $self->model->$writer($value);
$self->needs_sync(0);
};
};
implements fragment current_values {
- render hidden_value => over $_{viewport}->current_value_choices;
+ my $current_choices = $_{viewport}->current_value_choices;
+ if( @$current_choices ){
+ render hidden_value => over $current_choices;
+ } else {
+ arg field_name => event_id 'no_current_value';
+ arg '_' => {value => 1};
+ render 'hidden_value';
+ }
};
implements fragment selected_values {