X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FReaction%2FUI%2FViewPort%2FField%2FRole%2FMutable.pm;h=06e7e72b66a564c874acd766f944b954ee0530be;hb=28a7e0a73bb07c002464d6aabfc54c91339b00d1;hp=422c33b11f3643c3f2ec136d6659d74ecd67b2b6;hpb=3671c9c3a3eb9640371d09a80ff88ae774d0a0b7;p=catagits%2FReaction.git diff --git a/lib/Reaction/UI/ViewPort/Field/Role/Mutable.pm b/lib/Reaction/UI/ViewPort/Field/Role/Mutable.pm index 422c33b..06e7e72 100644 --- a/lib/Reaction/UI/ViewPort/Field/Role/Mutable.pm +++ b/lib/Reaction/UI/ViewPort/Field/Role/Mutable.pm @@ -30,8 +30,12 @@ sub adopt_value { $self->needs_sync(1); # if $self->has_attribute; } + sub can_sync_to_action { my $self = shift; + + # if field is already sync'ed, it can be sync'ed again + # this will make sync_to_action no-op if needs_sync is 0 return 1 unless $self->needs_sync; my $attr = $self->attribute; @@ -45,12 +49,20 @@ sub can_sync_to_action { } } } else { - return if $attr->is_required; + return if $self->model->attribute_is_required($attr); } return 1; }; + + sub sync_to_action { my ($self) = @_; + + # don't sync if we're already synced + return unless $self->needs_sync; + + # if we got here, needs_sync is 1 + # can_sync_to_action will do coercion checks, etc. return unless $self->can_sync_to_action; my $attr = $self->attribute;