# Copyright (c) 1999-2009 bivio Software, Inc. All rights reserved. # # Visit http://www.bivio.biz for more info. # # This library is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of the # License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; If not, you may get a copy from: # http://www.opensource.org/licenses/lgpl-license.html # # $Id: Select.pm,v 2.17 2011/05/10 20:44:47 moeller Exp $ package Bivio::UI::HTML::Widget::Select; use strict; use Bivio::Base 'HTMLWidget.MultipleChoice'; # C allows user to select from # a list of choices. # # auto_submit : boolean [0] # # Should a click submit the form? # # disabled : boolean [0] # # Make the selection read-only # # size : int [1] # # How many rows should be visible our($VERSION) = sprintf('%d.%02d', q$Revision: 2.17 $ =~ /\d+/g); my(@_ATTRS) = qw( auto_submit choices disabled enum_sort event_handler field form_model list_display_field list_id_field show_unknown size ); my($_F) = b_use('UI.Font'); sub accepts_attribute { # (proto, string) : boolean # Does the widget accept this attribute? my(undef, $attr) = @_; return grep($_ eq $attr, @_ATTRS); } sub render { # (self, any, Text_ref) : undef # Render the input field. First render is special, because we need # to extract the field's type and can only do that when we have a form. my($self, $source, $buffer) = @_; my($req) = $source->get_request; my($form) = $req->get_widget_value(@{$self->ancestral_get('form_model')}); my($field) = $self->get('field'); my($p, $s) = $_F->format_html('input_field', $req); $$buffer .= $p . ''.$s; return shift->SUPER::render(@_); } sub _load_items_from_provider { my($choices, $source) = @_; return [map( ($_, $_), map($choices->to_html($_), @{$choices->provide_select_choices($source)}), )]; } 1;