| 1 | package QBit::WebInterface::Controller::Form::Field::select; | ||
| 2 | $QBit::WebInterface::Controller::Form::Field::select::VERSION = '0.033'; | ||
| 3 | use qbit; | ||
| 4 | |||
| 5 | use base qw(QBit::WebInterface::Controller::Form::Field); | ||
| 6 | |||
| 7 | sub control_html { | ||
| 8 | my ($self) = @_; | ||
| 9 | |||
| 10 | my $html = '<select'; | ||
| 11 | $html .= $self->_class('span9'); | ||
| 12 | foreach (qw(id name style)) { | ||
| 13 | $html .= " $_=\"" . html_encode($self->{$_}) . '"' if defined($self->{$_}); | ||
| 14 | } | ||
| 15 | $html .= '>'; | ||
| 16 | |||
| 17 | $html .= '<option></option>' if $self->{'add_empty'}; | ||
| 18 | |||
| 19 | foreach my $option (@{$self->{'options'} || []}) { | ||
| 20 | $html .= '<option value="' . html_encode($option->{$self->{'items_key'}}) . '"'; | ||
| 21 | $html .= ' selected="selected"' | ||
| 22 | if defined($self->{'value'}) | ||
| 23 | && defined($option->{$self->{'items_key'}}) | ||
| 24 | && $self->{'value'} eq $option->{$self->{'items_key'}}; | ||
| 25 | $html .= '>' . html_encode($option->{$self->{'items_label'}}) . '</option>'; | ||
| 26 | } | ||
| 27 | |||
| 28 | |||
| 29 | $html .= '</select>'; | ||
| 30 | |||
| 31 | $html .= $self->_html_error(); | ||
| 32 | |||
| 33 | return $html; | ||
| 34 | } | ||
| 35 | |||
| 36 | TRUE; |