# 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: Radio.pm,v 2.10 2011/08/12 15:25:41 moeller Exp $ package Bivio::UI::HTML::Widget::Radio; use strict; use Bivio::Base 'HTMLWidget.Checkbox'; our($VERSION) = sprintf('%d.%02d', q$Revision: 2.10 $ =~ /\d+/g); my($_A) = b_use('IO.Alert'); my($_HTML) = b_use('Bivio.HTML'); sub initialize { my($self) = @_; if ($self->unsafe_get('value') && ! $self->unsafe_get('on_value')) { $_A->warn_deprecated('"value" deprecated, use "on_value" attribute'); $self->put(on_value => $self->get('value')); } $self->initialize_attr('on_value'); $self->initialize_attr(TYPE => 'radio'); return shift->SUPER::initialize(@_); } sub internal_input_base_render_attrs { my($self, $form, $field, $source, $buffer) = @_; shift->SUPER::internal_input_base_render_attrs(@_); my($value) = _on_value($self, $source); $value = ref($value) ? $value->to_html($value) : $_HTML->escape($value); $$buffer .= qq{ value="$value"}; return; } sub internal_is_checked { my($self, $form, $field, $source) = @_; return _on_value($self, $source) eq $form->get_field_type($field)->to_html($form->get($field)) ? 1 : 0; } sub internal_new_args { return shift->internal_compute_new_args([qw(field on_value label)], \@_); } sub internal_want_multi_check_handler { return 0; } sub _on_value { my($self, $source) = @_; return UNIVERSAL::isa($self->get('on_value'), 'Bivio::Type::Enum') ? $self->get('on_value')->to_html($self->get('on_value')) : ${$self->render_attr('on_value', $source)}; } 1;