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

Jifty commits jifty-commit at lists.jifty.org
Sat Oct 11 22:05:41 EDT 2008


Author: sunnavy
Date: Sat Oct 11 22:05:40 2008
New Revision: 5925

Modified:
   jifty/trunk/lib/Jifty/Web/Form/Field.pm
   jifty/trunk/lib/Jifty/Web/Form/Field/Select.pm

Log:
added multiple flag for select form field

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	Sat Oct 11 22:05:40 2008
@@ -118,8 +118,19 @@
 
 =cut
 
-sub accessors { shift->SUPER::accessors(), qw(name label input_name type sticky sticky_value default_value action mandatory ajax_validates ajax_canonicalizes autocompleter preamble hints placeholder focus render_mode max_length _element_id disable_autocomplete); }
-__PACKAGE__->mk_accessors(qw(name _label _input_name type sticky sticky_value default_value _action mandatory ajax_validates ajax_canonicalizes autocompleter preamble hints placeholder focus render_mode max_length _element_id disable_autocomplete));
+sub accessors {
+    shift->SUPER::accessors(), qw(name label input_name type
+      sticky sticky_value default_value action mandatory ajax_validates
+      ajax_canonicalizes autocompleter preamble hints placeholder focus
+      render_mode max_length _element_id disable_autocomplete multiple);
+}
+
+__PACKAGE__->mk_accessors(
+    qw(name _label _input_name type sticky sticky_value
+      default_value _action mandatory ajax_validates ajax_canonicalizes
+      autocompleter preamble hints placeholder focus render_mode
+      max_length _element_id disable_autocomplete multiple)
+);
 
 =head2 name [VALUE]
 
@@ -191,6 +202,11 @@
 
 Gets or sets the preamble located in front of the field.
 
+=head2 multiple [VALUE]
+
+A boolean indicating that the field is multiple.
+aka. has multiple attribute, which is uselful for select field.
+
 =head2 id 
 
 For the purposes of L<Jifty::Web::Form::Element>, the unique id of

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	Sat Oct 11 22:05:40 2008
@@ -25,13 +25,21 @@
     $field .= qq! title="@{[ $self->title ]}"! if ($self->title);
     $field .= $self->_widget_class;
     $field .= $self->javascript;
+    $field .= q! multiple="multiple"! if $self->multiple;
     $field .= qq!      >\n!;
+    my $current_value = $self->current_value;
+    Jifty->log->error( Data::Dumper::Dumper $current_value );
     for my $opt (@{ $self->action->available_values($self->name) }) {
         my $display = $opt->{'display'};
         my $value   = $opt->{'value'};
         $value = "" unless defined $value;
         $field .= qq!<option value="@{[ Jifty->web->escape($value) ]}"!;
-        $field .= qq! selected="selected"!  if defined $self->current_value and $self->current_value eq $value;
+        $field .= qq! selected="selected"!
+          if defined $current_value
+              && (
+                  ref $current_value eq 'ARRAY'
+                  ? ( grep { $value eq $_ } @$current_value )
+                  : $current_value eq $value );
         $field .= qq!>!;
         $field .= Jifty->web->escape(_($display)) if defined $display;
         $field .= qq!</option>\n!;


More information about the Jifty-commit mailing list