# Copyright (c) 1999-2008 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: DateField.pm,v 2.10 2010/12/03 22:27:13 moeller Exp $ package Bivio::UI::HTML::Widget::DateField; use strict; use Bivio::Base 'HTMLWidget.InputTextBase'; our($VERSION) = sprintf('%d.%02d', q$Revision: 2.10 $ =~ /\d+/g); my($_D) = b_use('Type.Date'); sub internal_input_base_render_attrs { my($self, $form, $field, $source, $buffer) = @_; shift->SUPER::internal_input_base_render_attrs(@_); my($v) = $form->in_error ? $form->get_field_as_html($field) : $_D->to_html($form->get($field) || ($self->render_simple_attr('allow_undef', $source) ? undef : $_D->local_today)); $$buffer .= qq{ value="$v"}; return; } sub initialize { my($self, $source) = @_; my($f) = $self->initialize_attr('field', undef, $source); $self->initialize_attr(size => $_D->get_width, $source); $self->initialize_attr(max_width => $_D->get_width, $source); $self->initialize_attr(allow_undef => sub { return b_use('HTMLWidget.Form') ->form_model_for_initialize($self, $source) ->get_field_constraint($f)->eq_none; }, $source); return shift->SUPER::initialize(@_); } sub internal_attributes { return [@{shift->SUPER::internal_attributes(@_)}, 'allow_undef']; } 1;