aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Reaction/UI/Widget/Field/Mutable.pm
blob: 9fc565e2ede6c44983037a63b3f4a38b644c7bbd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
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<Reaction::UI::Widget::Field> 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<value_string>.

=item field_name

Defaults to the C<field_id> argument unless already defined

=item field_type

Defaults to C<text>.

=item field_class

A string containing the joined class attribute. Defaults to
C<action-field> and the current viewport's C<name>.

=item exists_event

Contains the event id for C<exists>.

=item exists_value

Defaults to C<1>.

=back

=head2 message_fragment

Renders nothing if the viewport doesn't have a message.

Otherwise, the C<message> argument will be set to the localised string contained
in the viewport's C<message> attribute and the C<message> fragment will be rendered.

=head2 field_is_required

Will render either C<field_is_required_yes> or C<field_is_required_no> depending on
if C<value_is_required> on the viewport returns true and the viewports C<value_string>
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<span> element with a class attribute set to the C<field_class> argument.
The element contents will be the C<label_fragment>, C<field> and C<message_fragment>
fragments.

=item label

Builds a C<label> element with the C<for> attribute set to the value of C<field_id> and
the other attributes used from the C<field_is_required> argument. The content will be
the C<label> argument.

=item field_is_required_yes

Sets the class attribute to C<required_field>.

=item field_is_required_no

Empty.

=item message

Renders a C<span> element with the C<message> as content.

=item field

Renders the input field. The C<field_body> fragment is used to set the value.

=item field_body

Creates the C<value> attribute for the input element.

=back

=head2 default

  share/skin/default/layout/field/mutable.tt

The following layouts are provided:

=over 4

=item message

Will render the original C<message> fragment followed by a C<br> element.

=back

=head1 SUBCLASSES

=over 4

=item L<Reaction::UI::Widget::Field::Mutable::Boolean>

A widget allowing the manipulation of boolean values.

=item L<Reaction::UI::Widget::Field::Mutable::ChooseMany>

Allows the user to choose many items from a list of available values.

=item L<Reaction::UI::Widget::Field::Mutable::ChooseOne>

Allows the user to choose a single item from a list of available values.

=item L<Reaction::UI::Widget::Field::Mutable::DateTime>

A simple DateTime L<Reaction::UI::Widget::Field::Mutable> subclass.

=item L<Reaction::UI::Widget::Field::Mutable::File>

A simple file input field.

=item L<Reaction::UI::Widget::Field::Mutable::HiddenArray>

Renders an array reference value as a series of hidden fields.

=item L<Reaction::UI::Widget::Field::Mutable::Integer>

A simple integer L<Reaction::UI::Widget::Field::Mutable>.

=item L<Reaction::UI::Widget::Field::Mutable::MatchingPasswords>

Password input requiring that the password be entered twice, e.g. to input a new
password.

=item L<Reaction::UI::Widget::Field::Mutable::Password>

A password input L<Reaction::UI::Widget::Field::Mutable>.

=item L<Reaction::UI::Widget::Field::Mutable::Number>

A simple number L<Reaction::UI::Widget::Field::Mutable> input field.

=item L<Reaction::UI::Widget::Field::Mutable::String>

A simple string L<Reaction::UI::Widget::Field::Mutable> input field.

=item L<Reaction::UI::Widget::Field::Mutable::Text>

A multiline input L<Reaction::UI::Widget::Field::Mutable>.

=back

=head1 SEE ALSO

=over 4

=item * L<Reaction::UI::Widget::Field>

=back

=head1 AUTHORS

See L<Reaction::Class> for authors.

=head1 LICENSE

See L<Reaction::Class> for the license.

=cut