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

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Sun Sep 10 14:59:36 EDT 2006


Author: jesse
Date: Sun Sep 10 14:59:34 2006
New Revision: 1947

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

Log:
 r27331 at pinglin:  jesse | 2006-09-10 17:57:43 +0100
 * Made the display of a friendly string for picking a record from a list a lot more flexible. 
 * Now we do proper escaping of values in select-one lists.
 


Modified: jifty/trunk/lib/Jifty/Action/Record.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Action/Record.pm	(original)
+++ jifty/trunk/lib/Jifty/Action/Record.pm	Sun Sep 10 14:59:34 2006
@@ -176,6 +176,7 @@
 
                 $field_info->{ $field . "_confirm" } = {
                     render_as => 'Password',
+                    virtual => '1',
                     validator => $same,
                     mandatory => 0
                 };
@@ -190,11 +191,10 @@
                     );
                     $collection->unlimit;
 
-                    # XXX This assumes a ->name and a ->id method
+                    my $method = $refers_to->_brief_description();
+
                     $info->{valid_values} = [
-                        {   display_from => $refers_to->can('name')
-                            ? "name"
-                            : "id",
+                        {   display_from => $refers_to->can($method) ? $method : "id",
                             value_from => 'id',
                             collection => $collection
                         }

Modified: jifty/trunk/lib/Jifty/Record.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Record.pm	(original)
+++ jifty/trunk/lib/Jifty/Record.pm	Sun Sep 10 14:59:34 2006
@@ -306,10 +306,22 @@
     $self->SUPER::delete(@_); 
 }
 
+=head2 _brief_description
+
+When displaying a list of records, Jifty can display a friendly value 
+rather than the column's unique id.  Out of the box, Jifty always
+tries to display the 'name' field from the record. You can override this
+method to return the name of a method on your record class which will
+return a nice short human readable description for this record.
+
+=cut
+
+sub _brief_description {'name'}
+
 =head2 _to_record
 
-This is the SB function that is called when you fetch a value which C<REFERENCES> a
-Record class.  The only change from the SB code is the arguments to C<new>.
+This is the Jifty::DBI function that is called when you fetch a value which C<REFERENCES> a
+Record class.  The only change from the Jifty::DBI code is the arguments to C<new>.
 
 =cut
 

Modified: jifty/trunk/lib/Jifty/Web/Form/Field/Select.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web/Form/Field/Select.pm	(original)
+++ jifty/trunk/lib/Jifty/Web/Form/Field/Select.pm	Sun Sep 10 14:59:34 2006
@@ -22,11 +22,12 @@
         my $display = $opt->{'display'};
         my $value   = $opt->{'value'};
         $value = "" unless defined $value;
-        # TODO XXX FIXME worry about escape value, display?
         $field .= qq!<option value="$value"!;
         $field .= qq! selected="selected"!
             if defined $self->current_value and $self->current_value eq $value;
-        $field .= qq!>$display</option>\n!;
+        $field .= qq!>!;
+        $field .= HTML::Entities::encode_entities(_($display)) if defined $display;
+        $field .= qq!</option>\n!;
     } 
     $field .= qq!</select>\n!;
     Jifty->web->out($field);


More information about the Jifty-commit mailing list