| 1 | use warnings; | ||
| 2 | use strict; | ||
| 3 | |||
| 4 | package Jifty::Web::Form::Field::Combobox; | ||
| 5 | |||
| 6 | use base qw/Jifty::Web::Form::Field/; | ||
| 7 | |||
| 8 | =head1 NAME | ||
| 9 | |||
| 10 | Jifty::Web::Form::Field::Combobox - Add comboboxes to your forms | ||
| 11 | |||
| 12 | =head1 METHODS | ||
| 13 | |||
| 14 | =head2 render_widget | ||
| 15 | |||
| 16 | Renders the select widget. | ||
| 17 | |||
| 18 | =cut | ||
| 19 | |||
| 20 | sub render_widget { | ||
| 21 | my $self = shift; | ||
| 22 | my $title = $self->title ? qq! title="@{[ $self->title ]}"! | ||
| 23 | : qq! !; | ||
| 24 | |||
| 25 | my $field = <<"EOF"; | ||
| 26 | <nobr> | ||
| 27 | <span id="@{[ $self->element_id ]}_Container" class="combobox"> | ||
| 28 | <input name="@{[ $self->fallback_name ]}" | ||
| 29 | id="@{[ $self->element_id ]}" | ||
| 30 | $title | ||
| 31 | @{[ $self->_widget_class('combo-text')]} | ||
| 32 | value="@{[ $self->current_value ]}" | ||
| 33 | type="text" | ||
| 34 | size="30" | ||
| 35 | @{[ $self->javascript ]} | ||
| 36 | autocomplete="off" /><span id="@{[ $self->element_id ]}_Button" | ||
| 37 | @{[ $self->_widget_class('combo-button')]} | ||
| 38 | ></span></span><span style="display: none"></span><select | ||
| 39 | name="@{[ $self->input_name ]}" | ||
| 40 | id="@{[ $self->_element_id ]}_List" | ||
| 41 | @{[ $self->_widget_class('combo-list')]} | ||
| 42 | onchange="ComboBox_SimpleAttach(this, this.form['@{[ $self->element_id ]}']); " | ||
| 43 | > | ||
| 44 | <option style="display: none" value=""></option> | ||
| 45 | EOF | ||
| 46 | |||
| 47 | |||
| 48 | for my $opt ($self->available_values) { | ||
| 49 | my $display = ref($opt) ? $opt->{'display'} : $opt; | ||
| 50 | my $value = (ref($opt) ? $opt->{'value'} : $opt) || ''; | ||
| 51 | |||
| 52 | # TODO XXX FIXME worry about escape value, display? | ||
| 53 | $field .= qq!<option value="$value"!; | ||
| 54 | $field .= qq! selected="selected"! | ||
| 55 | if defined $self->current_value and $self->current_value eq $value; | ||
| 56 | $field .= qq!>$display</option>\n!; | ||
| 57 | } | ||
| 58 | |||
| 59 | |||
| 60 | |||
| 61 | $field .= <<"EOF"; | ||
| 62 | </select> | ||
| 63 | <script language="javascript"> | ||
| 64 | ComboBox_InitWith('@{[ $self->element_id ]}'); | ||
| 65 | </script> | ||
| 66 | </nobr> | ||
| 67 | EOF | ||
| 68 | |||
| 69 | |||
| 70 | |||
| 71 | Jifty->web->out($field); | ||
| 72 | ''; | ||
| 73 | } | ||
| 74 | |||
| 75 | |||
| 76 | =head2 render_autocomplete | ||
| 77 | |||
| 78 | Never render anything for autocomplete. | ||
| 79 | |||
| 80 | =cut | ||
| 81 | |||
| 82 | sub render_autocomplete {''} | ||
| 83 | |||
| 84 | 1; |