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

Jifty commits jifty-commit at lists.jifty.org
Mon Sep 7 11:14:40 EDT 2009


Author: ssinyagin
Date: Mon Sep  7 11:14:38 2009
New Revision: 7487

Added:
   jifty/trunk/lib/Jifty/Web/Form/Field/Checkboxes.pm
Modified:
   jifty/trunk/MANIFEST
   jifty/trunk/share/web/static/css/forms.css

Log:
List of checkboxes for multiple-choice selection

Modified: jifty/trunk/MANIFEST
==============================================================================
--- jifty/trunk/MANIFEST	(original)
+++ jifty/trunk/MANIFEST	Mon Sep  7 11:14:38 2009
@@ -339,6 +339,7 @@
 lib/Jifty/Web/Form/Field.pm
 lib/Jifty/Web/Form/Field/Button.pm
 lib/Jifty/Web/Form/Field/Checkbox.pm
+lib/Jifty/Web/Form/Field/Checkboxes.pm
 lib/Jifty/Web/Form/Field/Collection.pm
 lib/Jifty/Web/Form/Field/Combobox.pm
 lib/Jifty/Web/Form/Field/Date.pm

Added: jifty/trunk/lib/Jifty/Web/Form/Field/Checkboxes.pm
==============================================================================
--- (empty file)
+++ jifty/trunk/lib/Jifty/Web/Form/Field/Checkboxes.pm	Mon Sep  7 11:14:38 2009
@@ -0,0 +1,93 @@
+use warnings;
+use strict;
+ 
+package Jifty::Web::Form::Field::Checkboxes;
+
+use base qw/Jifty::Web::Form::Field/;
+
+=head1 NAME
+
+Jifty::Web::Form::Field::Checkboxes - Add a list of checkboxes for
+multiple-choice selection
+
+=head1 METHODS
+
+=head2 render_widget
+
+Renders the whole checkbox collection.
+
+=cut
+
+sub render_widget {
+    my $self  = shift;
+    $self->_render_checkboxes(0);
+}
+
+
+=head2 render_value
+
+Renders the whole checkbox collection in disabled mode.
+
+=cut
+
+sub render_value {
+    my $self  = shift;
+    $self->_render_checkboxes(1);
+}
+
+
+
+sub _render_checkboxes {
+    my $self  = shift;
+    my $readonly = shift;
+
+    my %checked;
+    
+    my $current_value = $self->current_value;
+    if( defined($current_value) ) {        
+        if( ref($current_value) eq 'ARRAY' ) {
+            for my $value (@$current_value) {
+                if( ref($value) eq 'HASH' ) {
+                    $value = $value->{'value'};
+                }
+                $checked{$value} = 1;
+            }
+        }
+    }
+                
+    Jifty->web->out('<ul class="checkboxlist">');
+    
+    for my $opt ($self->available_values) {
+     
+        my $display = ref($opt) ? $opt->{'display'} : $opt;
+        my $value   = ref($opt) ? $opt->{'value'} : $opt;
+        $value = '' if !defined($value);
+
+        my $id = $self->element_id . "-" . $value;
+        $id =~ s/\s+/_/;
+        my $field = qq! <li class="checkboxlistitem"> !;
+        $field .= qq! <input type="checkbox" !;
+        $field .= qq! name="@{[ $self->input_name ]}"!;
+        $field .= qq! id="@{[ $id ]}"!;
+        $field .= qq! title="@{[ $self->title ]}"! if ($self->title);
+        $field .= qq! value="@{[ $value ]}"!;
+        $field .= $self->_widget_class;
+        
+        $field .= qq! checked="checked"! if $checked{$value};
+        $field .= qq! disabled="disabled" readonly="readonly"! if $readonly;
+        
+        $field .= $self->javascript;
+        $field .= qq! /><label for="@{[ $id ]}"!;
+        $field .= $self->_widget_class;
+        $field .= qq!>$display</label>\n!;
+        $field = qq{<span class="checkboxlistitemlabel">$field</span></li>};
+        
+        Jifty->web->out($field);
+    }
+    Jifty->web->out('</ul>');
+}
+
+
+
+
+1;

Modified: jifty/trunk/share/web/static/css/forms.css
==============================================================================
--- jifty/trunk/share/web/static/css/forms.css	(original)
+++ jifty/trunk/share/web/static/css/forms.css	Mon Sep  7 11:14:38 2009
@@ -166,3 +166,11 @@
     font-weight: bold;
 }
 
+form ul.checkboxlist {
+    display: block;
+    float: left;
+}
+
+form ul.checkboxlist li.checkboxlistitem{
+    list-style-type: none;
+}


More information about the Jifty-commit mailing list