Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

allow widget_name_space to take a string in addition to arrayref

  • Loading branch information...
commit 0797b1ed1c6624a13a66467acefde48052c05177 1 parent fcc7765
@gshank authored
View
9 Changes
@@ -6,13 +6,18 @@
*** it's possible that this may break code if field values were being
set outside of FormHandler, or params were set on new. Pass params
on process. Set fields inside FormHandler, or run clear first, then
- set values.
+ set values. In general, it works best to update fields inside a
+ FormHandler class, in a method or method modifier.
+ Building results in 'new' happened originally because people expected
+ to be able to do $form->render after new, without process. But you're
+ better off always running 'process'.
Add flag 'no_preload' to skip building results in new (BUILD) if not needed
Add flag 'no_widgets' to skip applying widgets to fields if not needed
Fix for Date fields in compounds.
Types Printable & SingleWord use class messages
-
Add link to the bug tracker into the HELP section in the Pod.
+ Change how field_traits work: apply traits to field objects, add
+ new class method apply_traits (Stephen Thirlwall)
0.34001 Mon May 16, 2011
Fiz another memory cycle using Select field
View
2  lib/HTML/FormHandler.pm
@@ -724,7 +724,7 @@ sub build_result {
has 'field_traits' => ( is => 'ro', traits => ['Array'], isa => 'ArrayRef',
default => sub {[]}, handles => { 'has_field_traits' => 'count' } );
-has 'widget_name_space' => ( is => 'ro', isa => 'ArrayRef[Str]', default => sub {[]} );
+has 'widget_name_space' => ( is => 'ro', isa => 'Str|ArrayRef[Str]', default => sub {[]} );
has 'widget_form' => ( is => 'ro', isa => 'Str', default => 'Simple' );
has 'widget_wrapper' => ( is => 'ro', isa => 'Str', default => 'Simple' );
has 'no_widgets' => ( is => 'ro', isa => 'Bool' );
View
21 lib/HTML/FormHandler/Field.pm
@@ -862,14 +862,21 @@ has 'widget_tags' => (
},
);
has 'widget_name_space' => (
- traits => ['Array'],
- isa => 'ArrayRef[Str]',
- is => 'ro',
+ isa => 'Str|ArrayRef[Str]',
+ is => 'rw',
default => sub {[]},
- handles => {
- add_widget_name_space => 'push',
- },
);
+sub add_widget_name_space {
+ my ( $self, @ns ) = @_;
+ @ns = @{$ns[0]}if( scalar @ns && ref $ns[0] eq 'ARRAY' );
+ my $widget_ns = $self->widget_name_space;
+ if( ref $widget_ns eq 'ARRAY' ) {
+ push @{$self->widget_name_space}, @ns;
+ }
+ else {
+ $self->widget_name_space( [$widget_ns, @ns] );
+ }
+}
has 'order' => ( isa => 'Int', is => 'rw', default => 0 );
# 'inactive' is set in the field declaration, and is static. Default status.
has 'inactive' => ( isa => 'Bool', is => 'rw', clearer => 'clear_inactive' );
@@ -1129,7 +1136,7 @@ sub BUILD {
$self->_set_default( $self->_comp_default_meth )
if( $self->form && $self->form->can( $self->_comp_default_meth ) );
- $self->add_widget_name_space( @{$self->form->widget_name_space} ) if $self->form;
+ $self->add_widget_name_space( $self->form->widget_name_space ) if $self->form;
# widgets will already have been applied by BuildFields, but this allows
# testing individual fields
# $self->apply_rendering_widgets unless ($self->can('render') );
View
6 lib/HTML/FormHandler/Widget/ApplyRole.pm
@@ -19,8 +19,10 @@ sub get_widget_role {
my ( $self, $widget_name, $dir ) = @_;
my $widget_class = $self->widget_class($widget_name);
my $ldir = $dir ? '::' . $dir . '::' : '::';
- my @name_spaces = ( @{$self->widget_name_space},
- ('HTML::FormHandler::Widget', 'HTML::FormHandlerX::Widget') );
+
+ my $widget_ns = $self->widget_name_space;
+ my @name_spaces = ref $widget_ns eq 'ARRAY' ? @$widget_ns : $widget_ns;
+ push @name_spaces, ('HTML::FormHandler::Widget', 'HTML::FormHandlerX::Widget');
my @classes;
if ( $widget_class =~ s/^\+// )
{
View
2  t/field_traits.t
@@ -66,7 +66,7 @@ ok( $form->field('foo')->got_here && $form->field('bar')->got_here, 'base field
use HTML::FormHandler;
$form = HTML::FormHandler->new(
- widget_name_space => ['MyApp::Widget'],
+ widget_name_space => 'MyApp::Widget',
field_list => [
foo => { type => 'Text', required => 1, widget_attr => 'A Test!' },
baz => { type => 'Display', traits => ['My::Render'], my_attr => 'something' },
View
2  t/render_widgets.t
@@ -313,7 +313,7 @@ is( $form->field('boxed')->render, '<fieldset class="boxed"><legend>Boxed</legen
use HTML::FormHandler::Moose;
extends 'HTML::FormHandler';
- has '+widget_name_space' => ( default => sub { ['Widget'] } );
+ has '+widget_name_space' => ( default => 'Widget' );
has_field 'alpha' => ( widget => 'test_widget' );
has_field 'omega' => ( widget => 'Omega' );
Please sign in to comment.
Something went wrong with that request. Please try again.