[Jifty-commit] r4600 - in jifty/trunk: lib/Jifty/Web/Form lib/Jifty/Web/Form/Field

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Fri Nov 30 21:43:17 EST 2007


Author: sartak
Date: Fri Nov 30 21:43:14 2007
New Revision: 4600

Modified:
   jifty/trunk/   (props changed)
   jifty/trunk/lib/Jifty/Web/Form/Field.pm
   jifty/trunk/lib/Jifty/Web/Form/Field/Date.pm

Log:
 r48485 at onn:  sartak | 2007-11-30 21:43:07 -0500
 Add a canonicalize_value to Jifty::Web::Form::Field. Override it in Date to output just the YMD part.


Modified: jifty/trunk/lib/Jifty/Web/Form/Field.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web/Form/Field.pm	(original)
+++ jifty/trunk/lib/Jifty/Web/Form/Field.pm	Fri Nov 30 21:43:14 2007
@@ -489,7 +489,7 @@
     $field .= qq! name="@{[ $self->input_name ]}"! if ($self->input_name);
     $field .= qq! title="@{[ $self->title ]}"! if ($self->title);
     $field .= qq! id="@{[ $self->element_id ]}"!;
-    $field .= qq! value="@{[Jifty->web->escape($self->current_value)]}"! if defined $self->current_value;
+    $field .= qq! value="@{[$self->canonicalize_value(Jifty->web->escape($self->current_value))]}"! if defined $self->current_value;
     $field .= $self->_widget_class; 
     $field .= qq! size="@{[ $self->max_length() ]}" maxlength="@{[ $self->max_length() ]}"! if ($self->max_length());
     $field .= qq! autocomplete="off"! if defined $self->disable_autocomplete;
@@ -501,6 +501,17 @@
 }
 
 
+=head2 canonicalize_value
+
+Called when a value is about to be displayed. Can be overridden to, for example,
+display only the yyyy-mm-dd portion of a DateTime.
+
+=cut
+
+sub canonicalize_value {
+    my $self = shift;
+    return $_[0];
+}
 
 =head2 other_widget_properties
 
@@ -551,7 +562,7 @@
     my $field = '<span';
     $field .= qq! class="@{[ $self->classes ]}"> !;
     # XXX: force stringify the value because maketext is buggy with overloaded objects.
-    $field .= Jifty->web->escape("@{[$self->current_value]}") if defined $self->current_value;
+    $field .= $self->canonicalize_value(Jifty->web->escape("@{[$self->current_value]}")) if defined $self->current_value;
     $field .= qq!</span>\n!;
     Jifty->web->out($field);
     return '';

Modified: jifty/trunk/lib/Jifty/Web/Form/Field/Date.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web/Form/Field/Date.pm	(original)
+++ jifty/trunk/lib/Jifty/Web/Form/Field/Date.pm	Fri Nov 30 21:43:14 2007
@@ -34,4 +34,22 @@
 }
 
 
+=head2 canonicalize_value
+
+If the value is a DateTime, return just the ymd portion of it.
+
+=cut
+
+sub canonicalize_value {
+    my $self  = shift;
+    my $value = $self->current_value;
+
+    if (UNIVERSAL::isa($value, 'DateTime')) {
+        $value = $value->ymd;
+    }
+
+    return $value;
+}
+
+
 1;


More information about the Jifty-commit mailing list