package Reaction::UI::Widget::Field::Mutable; use Reaction::UI::WidgetClass; use namespace::clean -except => [ qw(meta) ]; extends 'Reaction::UI::Widget::Field'; before fragment widget { arg 'field_id' => event_id 'value_string'; arg 'field_name' => event_id 'value_string' unless defined $_{field_name}; arg 'field_type' => 'text'; arg 'field_class' => "action-field " . $_{viewport}->name; # these two are to fire force_events in viewports # where you can end up without an event for e.g. # HTML checkbox fields arg 'exists_event' => event_id 'exists'; arg 'exists_value' => 1; }; implements fragment message_fragment { my $vp = $_{viewport}; return unless $vp->has_message; my $message = $vp->message; if ($message) { arg message => localized $message; render 'message'; } }; implements fragment field_is_required { my $vp = $_{viewport}; if ( $vp->value_is_required && !$vp->value_string ) { render 'field_is_required_yes'; } else { render 'field_is_required_no'; } }; __PACKAGE__->meta->make_immutable; 1; __END__; =head1 NAME Reaction::UI::Widget::Field::Mutable - Mutable fields =head1 DESCRIPTION An extension of L representing fields whose values can be mutated. =head1 FRAGMENTS =head2 widget The following additional arguments are provided: =over 4 =item field_id Contains the viewport's event id for C. =item field_name Defaults to the C argument unless already defined =item field_type Defaults to C. =item field_class A string containing the joined class attribute. Defaults to C and the current viewport's C. =item exists_event Contains the event id for C. =item exists_value Defaults to C<1>. =back =head2 message_fragment Renders nothing if the viewport doesn't have a message. Otherwise, the C argument will be set to the localised string contained in the viewport's C attribute and the C fragment will be rendered. =head2 field_is_required Will render either C or C depending on if C on the viewport returns true and the viewports C is empty. =head1 LAYOUT SETS =head2 base share/skin/base/layout/field/mutable.tt The following layouts are provided: =over 4 =item widget Builds a C element with a class attribute set to the C argument. The element contents will be the C, C and C fragments. =item label Builds a C