21ce041a90d3198c0390003e7fdb719538834b6f
[catagits/Reaction.git] / lib / Reaction / UI / Widget / Field / Mutable / ChooseOne.pm
1 package Reaction::UI::Widget::Field::Mutable::ChooseOne;
2
3 use Reaction::UI::WidgetClass;
4
5 use namespace::clean -except => [ qw(meta) ];
6 extends 'Reaction::UI::Widget::Field::Mutable';
7
8
9
10 implements fragment option_is_required {
11   if ($_{viewport}->value_is_required) {
12     render 'option_is_required_yes';
13   } else {
14     render 'option_is_required_no';
15   }
16 };
17
18 implements fragment option_list {
19   render option => over $_{viewport}->value_choices;
20 };
21
22 implements fragment option {
23   arg option_name => $_->{name};
24   arg option_value => $_->{value};
25 };
26
27 implements fragment option_is_selected {
28   if ($_{viewport}->is_current_value($_->{value})) {
29     render 'option_is_selected_yes';
30   } else {
31     render 'option_is_selected_no';
32   }
33 };
34
35 __PACKAGE__->meta->make_immutable;
36
37
38 1;
39
40 __END__;
41
42 =head1 NAME
43
44 Reaction::UI::Widget::Field::Mutable::ChooseOne - Choose one from a list of available values
45
46 =head1 DESCRIPTION
47
48 See L<Reaction::UI::Widget::Field::Mutable>. This widget provides the user with a 
49 field where he can select a single value from a list of many.
50
51 =head1 FRAGMENTS
52
53 =head2 field
54
55 Renders a series fragment C<option> for each C<value_choices> in the viewport
56
57 Additional varibles set: C<is_required> - Boolean, self-explanatory
58
59 =head2 option
60
61 C<content> is a dummy variable, but th additional variables C<v_value>, C<v_name>
62 and C<is_selected> are set
63
64 =head2 option_is_required
65
66 Renders either C<option_is_required_yes> or C<option_is_required_no> depending on
67 the viewport's C<value_is_required> attribute.
68
69 =head2 option_list
70
71 Renders the C<option> fragment over the viewport's C<value_choices>. This populates
72 the list of available values.
73
74 =head2 option_is_selected
75
76 Renders either C<option_is_selected_yes> or C<option_is_selected_no> depending on
77 if the viewport's C<is_current_value> method returns true on the current topic
78 arguments C<value> key.
79
80 =head1 LAYOUT SETS
81
82 =head2 base
83
84   share/skin/base/layout/field/mutable/choose_one.tt
85
86 This layout set renders a C<select> element with the available values as C<option>s.
87
88 =head1 AUTHORS
89
90 See L<Reaction::Class> for authors.
91
92 =head1 LICENSE
93
94 See L<Reaction::Class> for the license.
95
96 =cut