do not include .git directory
[catagits/Reaction.git] / lib / Reaction / UI / Widget / Field / Mutable.pm
CommitLineData
2f670e13 1package Reaction::UI::Widget::Field::Mutable;
2
3use Reaction::UI::WidgetClass;
4
bae75bee 5use namespace::clean -except => [ qw(meta) ];
6extends 'Reaction::UI::Widget::Field';
7
8
9
10 before fragment widget {
11 arg 'field_id' => event_id 'value_string';
12 arg 'field_name' => event_id 'value_string' unless defined $_{field_name};
13 arg 'field_type' => 'text';
14 arg 'field_class' => "action-field " . $_{viewport}->name;
15
16 # these two are to fire force_events in viewports
17 # where you can end up without an event for e.g.
18 # HTML checkbox fields
19
20 arg 'exists_event' => event_id 'exists';
21 arg 'exists_value' => 1;
22 };
23
24 implements fragment message_fragment {
b44e101f 25 my $vp = $_{viewport};
c72dfafb 26 return unless $vp->has_message;
27 my $message = $vp->message;
b44e101f 28 if ($message) {
d219104c 29 arg message => localized $message;
bae75bee 30 render 'message';
31 }
32 };
33
34 implements fragment field_is_required {
39453d9d 35 my $vp = $_{viewport};
36 if ( $vp->value_is_required && !$vp->value_string ) {
bae75bee 37 render 'field_is_required_yes';
38 } else {
39 render 'field_is_required_no';
40 }
41 };
42
43__PACKAGE__->meta->make_immutable;
44
2f670e13 45
461;
47
48__END__;
f9b32c83 49
50=head1 NAME
51
52Reaction::UI::Widget::Field::Mutable - Mutable fields
53
54=head1 DESCRIPTION
55
56An extension of L<Reaction::UI::Widget::Field> representing fields
57whose values can be mutated.
58
59=head1 FRAGMENTS
60
61=head2 widget
62
63The following additional arguments are provided:
64
65=over 4
66
67=item field_id
68
69Contains the viewport's event id for C<value_string>.
70
71=item field_name
72
73Defaults to the C<field_id> argument unless already defined
74
75=item field_type
76
77Defaults to C<text>.
78
79=item field_class
80
81A string containing the joined class attribute. Defaults to
82C<action-field> and the current viewport's C<name>.
83
84=item exists_event
85
86Contains the event id for C<exists>.
87
88=item exists_value
89
90Defaults to C<1>.
91
92=back
93
94=head2 message_fragment
95
96Renders nothing if the viewport doesn't have a message.
97
98Otherwise, the C<message> argument will be set to the localised string contained
99in the viewport's C<message> attribute and the C<message> fragment will be rendered.
100
101=head2 field_is_required
102
103Will render either C<field_is_required_yes> or C<field_is_required_no> depending on
104if C<value_is_required> on the viewport returns true and the viewports C<value_string>
105is empty.
106
107=head1 LAYOUT SETS
108
109=head2 base
110
111 share/skin/base/layout/field/mutable.tt
112
113The following layouts are provided:
114
115=over 4
116
117=item widget
118
119Builds a C<span> element with a class attribute set to the C<field_class> argument.
120The element contents will be the C<label_fragment>, C<field> and C<message_fragment>
121fragments.
122
123=item label
124
125Builds a C<label> element with the C<for> attribute set to the value of C<field_id> and
126the other attributes used from the C<field_is_required> argument. The content will be
127the C<label> argument.
128
129=item field_is_required_yes
130
131Sets the class attribute to C<required_field>.
132
133=item field_is_required_no
134
135Empty.
136
137=item message
138
139Renders a C<span> element with the C<message> as content.
140
141=item field
142
143Renders the input field. The C<field_body> fragment is used to set the value.
144
145=item field_body
146
147Creates the C<value> attribute for the input element.
148
149=back
150
151=head2 default
152
153 share/skin/default/layout/field/mutable.tt
154
155The following layouts are provided:
156
157=over 4
158
159=item message
160
161Will render the original C<message> fragment followed by a C<br> element.
162
163=back
164
165=head1 SUBCLASSES
166
167=over 4
168
169=item L<Reaction::UI::Widget::Field::Mutable::Boolean>
170
171A widget allowing the manipulation of boolean values.
172
173=item L<Reaction::UI::Widget::Field::Mutable::ChooseMany>
174
175Allows the user to choose many items from a list of available values.
176
177=item L<Reaction::UI::Widget::Field::Mutable::ChooseOne>
178
179Allows the user to choose a single item from a list of available values.
180
181=item L<Reaction::UI::Widget::Field::Mutable::DateTime>
182
183A simple DateTime L<Reaction::UI::Widget::Field::Mutable> subclass.
184
185=item L<Reaction::UI::Widget::Field::Mutable::File>
186
187A simple file input field.
188
189=item L<Reaction::UI::Widget::Field::Mutable::HiddenArray>
190
191Renders an array reference value as a series of hidden fields.
192
193=item L<Reaction::UI::Widget::Field::Mutable::Integer>
194
195A simple integer L<Reaction::UI::Widget::Field::Mutable>.
196
197=item L<Reaction::UI::Widget::Field::Mutable::MatchingPasswords>
198
199Password input requiring that the password be entered twice, e.g. to input a new
200password.
201
202=item L<Reaction::UI::Widget::Field::Mutable::Password>
203
204A password input L<Reaction::UI::Widget::Field::Mutable>.
205
206=item L<Reaction::UI::Widget::Field::Mutable::Number>
207
208A simple number L<Reaction::UI::Widget::Field::Mutable> input field.
209
210=item L<Reaction::UI::Widget::Field::Mutable::String>
211
212A simple string L<Reaction::UI::Widget::Field::Mutable> input field.
213
214=item L<Reaction::UI::Widget::Field::Mutable::Text>
215
216A multiline input L<Reaction::UI::Widget::Field::Mutable>.
217
218=back
219
220=head1 SEE ALSO
221
222=over 4
223
224=item * L<Reaction::UI::Widget::Field>
225
226=back
227
228=head1 AUTHORS
229
230See L<Reaction::Class> for authors.
231
232=head1 LICENSE
233
234See L<Reaction::Class> for the license.
235
236=cut