Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

initial pass at Bootstrap3 wrapper

  • Loading branch information...
commit fb8fddcabd12bb3241fea862b8eb10006e028464 1 parent e6039db
Gerda Shank authored
19 Changes
View
@@ -1,3 +1,22 @@
+0.40050
+ *** 'widget_tags' in a field have been deprecated for a long time; removing.
+ There are still widget_tags in the form and compound fields.
+ Use 'tags' in a field instead.
+ *** Initial support of Bootstrap3 - still EXPERIMENTAL. Do not use in
+ production yet. Changes in interface may occur over the next few weeks.
+ Supporting Bootstrap 3.0 required a surprising amount of minor refactoring:
+ Checkboxes and radio elements now have an additional div wrapping them.
+ This required setting flags in the wrapper that could be seen by the
+ field widgets. Used 'wrapper_tags' attribute, which is not the most satisfying
+ solution but does work. The former 'controls' div now doesn't have the
+ 'controls' class, but is used for sizing. Added new attribute
+ 'element_wrapper_class' to provide these classes. Split out addition of
+ classes to the wrapper and element into 'add_standard_wrapper_classes' and
+ 'add_standard_element_classes', because B3.0 now wants 'has-error' and
+ 'has-warning' instead of the former 'error' class. 'control-group' was
+ changed to 'form-group'. The 'form-control' class has been added to
+ text, passowrd, textarea, and select fields.
+
0.40028 Sat Sep 21, 2013
Fixed bug when rendering blocks with 'run' (results)
Sort the deflated values of SelectCSV field
10 lib/HTML/FormHandler.pm
View
@@ -1032,16 +1032,6 @@ sub has_flag {
return $self->$flag_name;
}
-# used to transfer tags to fields from form
-has 'widget_tags' => (
- isa => 'HashRef',
- traits => ['Hash'],
- is => 'rw',
- default => sub {{}},
- handles => {
- has_widget_tags => 'count'
- }
-);
has 'form_tags' => (
traits => ['Hash'],
isa => 'HashRef',
76 lib/HTML/FormHandler/Field.pm
View
@@ -234,12 +234,16 @@ function (from HTML::FormHandler::Render::Util) and passing in a method that
adds in error classes, provides backward compatibility with the deprecated
attributes, etc.
- attribute hashref class attribute wrapping method
- ================= ================= ================
- element_attr element_class element_attributes
- label_attr label_class label_attributes
- wrapper_attr wrapper_class wrapper_attributes
-
+ attribute hashref class attribute wrapping method
+ ================= ================= ================
+ element_attr element_class element_attributes
+ label_attr label_class label_attributes
+ wrapper_attr wrapper_class wrapper_attributes
+ element_wrapper_class element_wrapper_attributes
+
+('element_wrapper' is for an inner div around the input element, not
+including the label. Used for Bootstrap3 rendering, but also available
+in the Simple wrapper.)
The slots for the class attributes are arrayrefs; they will coerce a
string into an arrayref.
In addition, these 'wrapping methods' call a hook method in the form class,
@@ -268,7 +272,7 @@ This attribute used to be named 'widget_tags', which is deprecated.
=head2 html5_type_attr [string]
-This string is used when rendering the input tag as the value for the type attribute.
+This string is used when rendering an input element as the value for the type attribute.
It is used when the form has the is_html5 flag on.
=head2 widget
@@ -780,16 +784,17 @@ sub uwrapper { ucc_widget( shift->widget_wrapper || '' ) || 'simple' }
sub twrapper { shift->uwrapper . ".tt" }
sub uwidget { ucc_widget( shift->widget || '' ) || 'simple' }
sub twidget { shift->uwidget . ".tt" }
-# deprecated. use 'tags' instead.
-has 'widget_tags' => (
+# for use of wrapper classes
+has 'wrapper_tags' => (
isa => 'HashRef',
traits => ['Hash'],
is => 'rw',
- default => sub {{}},
+ builder => 'build_wrapper_tags',
handles => {
- has_widget_tags => 'count'
+ has_wrapper_tags => 'count'
}
);
+sub build_wrapper_tags { {} }
has 'tags' => (
traits => ['Hash'],
isa => 'HashRef',
@@ -863,6 +868,7 @@ has 'disabled' => ( isa => 'Bool', is => 'rw' );
has 'readonly' => ( isa => 'Bool', is => 'rw' );
has 'tabindex' => ( is => 'rw', isa => 'Int' );
+sub html_element { 'input' }
has 'type_attr' => ( is => 'rw', isa => 'Str', default => 'text' );
has 'html5_type_attr' => ( isa => 'Str', is => 'ro', default => 'text' );
sub input_type {
@@ -925,6 +931,31 @@ sub set_html_attr { shift->set_element_attr(@_) }
}
}
+# we're assuming that the only attribute we want in an element wrapper is a class
+has 'element_wrapper_class' => (
+ is => 'rw', isa => 'HFH::ArrayRefStr',
+ traits => ['Array'],
+ coerce => 1,
+ builder => "build_element_wrapper_class",
+ handles => {
+ has_element_wrapper_class => 'count',
+ _add_element_wrapper_class => 'push',
+ },
+);
+sub add_element_wrapper_class { shift->_add_element_wrapper_class((ref $_[0] eq 'ARRAY' ? @{$_[0]} : @_)); }
+sub build_element_wrapper_class { [] }
+sub element_wrapper_attributes {
+ my ( $self, $result ) = @_;
+ $result ||= $self->result;
+ # local copy of label_attr
+ my $attr = {};
+ my $class = [@{$self->element_wrapper_class}];
+ $attr->{class} = $class if @$class;
+ # call form hook
+ my $mod_attr = $self->form->html_attributes($self, 'element_wrapper', $attr, $result) if $self->form;
+ return ref($mod_attr) eq 'HASH' ? $mod_attr : $attr;
+}
+
sub attributes { shift->element_attributes(@_) }
sub element_attributes {
my ( $self, $result ) = @_;
@@ -945,15 +976,20 @@ sub element_attributes {
}
$attr = {%$attr, %{$self->element_attr}};
my $class = [@{$self->element_class}];
- push @$class, 'error' if $result->has_errors;
- push @$class, 'warning' if $result->has_warnings;
- push @$class, 'disabled' if $self->disabled;
+ $self->add_standard_element_classes($result, $class);
$attr->{class} = $class if @$class;
# call form hook
my $mod_attr = $self->form->html_attributes($self, 'element', $attr, $result) if $self->form;
return ref($mod_attr) eq 'HASH' ? $mod_attr : $attr;
}
+sub add_standard_element_classes {
+ my ( $self, $result, $class ) = @_;
+ push @$class, 'error' if $result->has_errors;
+ push @$class, 'warning' if $result->has_warnings;
+ push @$class, 'disabled' if $self->disabled;
+}
+
sub label_attributes {
my ( $self, $result ) = @_;
$result ||= $self->result;
@@ -973,8 +1009,7 @@ sub wrapper_attributes {
my $attr = {%{$self->wrapper_attr}};
my $class = [@{$self->wrapper_class}];
# add 'error' to class
- push @$class, 'error' if ( $result->has_error_results || $result->has_errors );
- push @$class, 'warning' if $result->has_warnings;
+ $self->add_standard_wrapper_classes($result, $class);
$attr->{class} = $class if @$class;
# add id if compound field and id doesn't exist unless 'no_wrapper_id' tag
$attr->{id} = $self->id
@@ -984,6 +1019,13 @@ sub wrapper_attributes {
return ref($mod_attr) eq 'HASH' ? $mod_attr : $attr;
}
+sub add_standard_wrapper_classes {
+ my ( $self, $result, $class ) = @_;
+ push @$class, 'error' if ( $result->has_error_results || $result->has_errors );
+ push @$class, 'warning' if $result->has_warnings;
+}
+
+
sub wrapper_tag {
my $self = shift;
return $self->get_tag('wrapper_tag') || 'div';
@@ -1261,7 +1303,7 @@ sub BUILD {
my ( $self, $params ) = @_;
# temporary, for compatibility. move widget_tags to tags
- $self->merge_tags($self->widget_tags) if $self->has_widget_tags;
+ $self->merge_tags($self->wrapper_tags) if $self->has_wrapper_tags;
# run default method builder
$self->build_default_method;
# build validate_method; needs to happen before validation
1  lib/HTML/FormHandler/Field/Select.pm
View
@@ -394,6 +394,7 @@ has 'active_column' => ( isa => 'Str', is => 'rw', default => 'active'
has 'auto_widget_size' => ( isa => 'Int', is => 'rw', default => '0' );
has 'sort_column' => ( isa => 'Str|ArrayRef[Str]', is => 'rw' );
has '+widget' => ( default => 'Select' );
+sub html_element { 'select' }
has '+type_attr' => ( default => 'select' );
has 'empty_select' => ( isa => 'Str', is => 'rw' );
has '+deflate_method' => ( default => sub { \&select_deflate } );
1  lib/HTML/FormHandler/Field/TextArea.pm
View
@@ -8,6 +8,7 @@ our $VERSION = '0.02';
has '+widget' => ( default => 'Textarea' );
has 'cols' => ( isa => 'Int', is => 'rw' );
has 'rows' => ( isa => 'Int', is => 'rw' );
+sub html_element { 'textarea' }
=head1 Summary
11 lib/HTML/FormHandler/Fields.pm
View
@@ -67,6 +67,17 @@ has 'update_subfields' => ( is => 'rw', isa => 'HashRef', builder => 'build_upda
has_update_subfields => 'count' } );
sub build_update_subfields {{}}
+# used to transfer tags to fields from form and compound fields
+has 'widget_tags' => (
+ isa => 'HashRef',
+ traits => ['Hash'],
+ is => 'rw',
+ default => sub {{}},
+ handles => {
+ has_widget_tags => 'count'
+ }
+);
+
# compatibility wrappers for result errors
sub error_fields {
my $self = shift;
2  lib/HTML/FormHandler/Widget/Field/ButtonTag.pm
View
@@ -5,6 +5,8 @@ use Moose::Role;
use namespace::autoclean;
use HTML::FormHandler::Render::Util ('process_attrs');
+sub html_element { 'button' }
+
sub render_element {
my ( $self, $result ) = @_;
$result ||= $self->result;
16 lib/HTML/FormHandler/Widget/Field/RadioGroup.pm
View
@@ -12,6 +12,8 @@ Tags: radio_br_after
=cut
+sub type_attr { 'radio' }
+
sub render {
my ( $self, $result ) = @_;
$result ||= $self->result;
@@ -96,9 +98,17 @@ sub wrap_radio {
# return wrapped radio, either on left or right
my $label = $self->_localize($option_label);
- return qq{<label$lattrs$for>\n$label\n$rendered_widget</label>}
- if( $self->get_tag('label_left') );
- return qq{<label$lattrs$for>$rendered_widget\n$label\n</label>};
+ my $output = '';
+ if ( $self->get_tag('label_left') ) {
+ $output = qq{<label$lattrs$for>\n$label\n$rendered_widget</label>};
+ }
+ else {
+ $output = qq{<label$lattrs$for>$rendered_widget\n$label\n</label>};
+ }
+ if ( $self->get_tag('radio_element_wrapper') ) {
+ $output = qq{<div class="radio">$output</div>};
+ }
+ return $output;
}
1;
14 lib/HTML/FormHandler/Widget/Wrapper/Base.pm
View
@@ -57,9 +57,17 @@ sub wrap_checkbox {
my $lattrs = process_attrs( { class => \@label_class } );
# return wrapped checkbox, either on left or right
- return qq{<label$lattrs$for>\n$label\n$rendered_widget</label>}
- if( $self->get_tag('label_left') );
- return qq{<label$lattrs$for>$rendered_widget\n$label\n</label>};
+ my $output = '';
+ if ( $self->get_tag('label_left') ) {
+ $output = qq{<label$lattrs$for>\n$label\n$rendered_widget</label>};
+ }
+ else {
+ $output = qq{<label$lattrs$for>$rendered_widget\n$label\n</label>};
+ }
+ if ( $self->get_tag('checkbox_element_wrapper') ) {
+ $output = qq{<div class="checkbox">$output</div>};
+ }
+ return $output;
}
# for compatibility with older code
173 lib/HTML/FormHandler/Widget/Wrapper/Bootstrap3.pm
View
@@ -0,0 +1,173 @@
+package HTML::FormHandler::Widget::Wrapper::Bootstrap3;
+# ABSTRACT: Twitter Bootstrap 2.0 field wrapper
+
+use Moose::Role;
+use namespace::autoclean;
+use HTML::FormHandler::Render::Util ('process_attrs');
+
+with 'HTML::FormHandler::Widget::Wrapper::Base';
+
+=head1 SYNOPSIS
+
+Wrapper to implement Bootstrap 3.0 style form element rendering.
+
+=head1 DESCRIPTION
+
+Differences from the Bootstrap 2.0 wrapper:
+
+ The wrapper class is 'form-group' instead of 'control-group'
+ The div wrapping the form element does not
+ have the 'controls' class. Used for sizing css classes.
+ Input prepend & append use different classes
+ The input elements have a 'form-control' class
+
+Tags supported:
+
+ label_no_filter -- don't html filter the label
+ label_after -- useful for putting a colon, or other trailing formatting
+ before_element -- insert tag before input, outside element's control div
+ before_element_inside_div -- insert tag before input element, inside control div
+ input_prepend -- for Bootstrap 'input-prepend' class
+ input_append -- for Bootstrap 'input-append' class
+ input_append_button -- 'input-append' with button instead of span
+ no_errors -- don't append error to field rendering
+ after_element -- insert tag after input element
+
+=cut
+
+sub build_wrapper_tags {
+ {
+ radio_element_wrapper => 1,
+ checkbox_element_wrapper => 1,
+ }
+}
+
+sub wrap_field {
+ my ( $self, $result, $rendered_widget ) = @_;
+
+ my $output;
+
+ # create attribute string for wrapper
+ if ( $self->do_wrapper ) {
+ my $attr = $self->wrapper_attributes($result);
+ # no 'control-group' class for Hidden fields, 'form-actions' for submit/reset
+ my $div_class = 'form-group';
+ unshift @{$attr->{class}}, $div_class;
+ my $attr_str = process_attrs( $attr );
+ # wrapper is always a div
+ $output .= $self->get_tag('before_wrapper');
+ $output .= qq{\n<div$attr_str>};
+ }
+ # render the label
+ $output .= "\n" . $self->do_render_label($result, undef, ['control-label'] )
+ if $self->do_label;
+ $output .= $self->get_tag('before_element');
+
+ # the controls div; used to have 'controls' class. Now it comes from
+ # the 'element_wrapper_class'
+ my $ew_attr = $self->element_wrapper_attributes($result);
+ my $element_wrapper_attrs = process_attrs( $ew_attr );
+ $output .= qq{\n<div$element_wrapper_attrs>}
+ unless !$self->do_wrapper;
+
+ # yet another tag
+ $output .= $self->get_tag('before_element_inside_div');
+ # handle input-prepend and input-append
+ if( $self->get_tag('input_prepend') || $self->get_tag('input_append') ||
+ $self->get_tag('input_append_button') ) {
+ $rendered_widget = $self->do_prepend_append($rendered_widget);
+ }
+ elsif( lc $self->widget eq 'checkbox' ) {
+ $rendered_widget = $self->wrap_checkbox($result, $rendered_widget, 'label')
+ }
+
+ $output .= "\n$rendered_widget";
+ # various 'help-inline' bits: errors, warnings
+ unless( $self->get_tag('no_errors') ) {
+ $output .= qq{\n<span class="help-block">$_</span>}
+ for $result->all_errors;
+ $output .= qq{\n<span class="help-block">$_</span>} for $result->all_warnings;
+ }
+ # extra after element stuff
+ $output .= $self->get_tag('after_element');
+ # close element_wrapper 'control' div
+ $output .= '</div>' unless !$self->do_wrapper;
+ # close wrapper
+ if ( $self->do_wrapper ) {
+ $output .= "\n</div>";
+ $output .= $self->get_tag('after_wrapper');
+ }
+ return "$output";
+}
+
+# don't render label for checkboxes
+sub do_render_label {
+ my ( $self ) = @_;
+
+ return '' if $self->type_attr eq 'checkbox';
+ HTML::FormHandler::Widget::Wrapper::Base::do_render_label(@_);
+}
+
+sub add_standard_element_classes {
+ my ( $self, $result, $class ) = @_;
+ push @$class, 'has-error' if $result->has_errors;
+ push @$class, 'has-warning' if $result->has_warnings;
+ push @$class, 'disabled' if $self->disabled;
+ push @$class, 'form-control'
+ if $self->html_element eq 'select' || $self->html_element eq 'textarea' ||
+ $self->type_attr eq 'text' || $self->type_attr eq 'password';
+}
+
+sub add_standard_wrapper_classes {
+ my ( $self, $result, $class ) = @_;
+ push @$class, 'has-error' if ( $result->has_error_results || $result->has_errors );
+ push @$class, 'has-warning' if $result->has_warnings;
+ # TODO: has-success?
+}
+
+sub wrap_checkbox {
+ my ( $self, $result, $rendered_widget ) = @_;
+
+ # use the regular label
+ my $label = $self->option_label || $self->label;
+ $label = $self->html_filter($self->_localize($label));
+ my $id = $self->id;
+ my $for = qq{ for="$id"};
+
+ # return wrapped checkbox, either on left or right
+ return qq{<div class="checkbox"><label$for>\n$label\n$rendered_widget</label></div>}
+ if( $self->get_tag('label_left') );
+ return qq{<div class="checkbox"><label$for>$rendered_widget\n$label\n</label></div>};
+}
+
+sub do_prepend_append {
+ my ( $self, $rendered_widget ) = @_;
+
+ my @class;
+ if( my $ip_tag = $self->get_tag('input_prepend' ) ) {
+ $rendered_widget = qq{<span class="input-group-addon">$ip_tag</span>$rendered_widget};
+ push @class, 'input-group';
+ }
+ if ( my $ia_tag = $self->get_tag('input_append' ) ) {
+ $rendered_widget = qq{$rendered_widget<span class="input-group-addon">$ia_tag</span>};
+ push @class, 'input-group';
+ }
+ if ( my $iab_tag = $self->get_tag('input_append_button') ) {
+ my @buttons = ref $iab_tag eq 'ARRAY' ? @$iab_tag : ($iab_tag);
+ my $group = qq{<span class="input-group-btn">};
+ foreach my $btn ( @buttons ) {
+ $group = qq{<button type="button" class="btn">$btn</button>};
+ }
+ $group .= qq{</span>};
+ $rendered_widget = qq{$rendered_widget$group};
+ push @class, 'input-group';
+ }
+ my $attr = process_attrs( { class => \@class } );
+ $rendered_widget =
+qq{<div$attr>
+ $rendered_widget
+</div>};
+ return $rendered_widget;
+}
+
+1;
22 lib/HTML/FormHandler/Widget/Wrapper/Simple.pm
View
@@ -70,12 +70,26 @@ sub wrap_field {
if $self->do_label;
# append 'before_element'
$output .= $self->get_tag('before_element');
- # start control div
- $output .= qq{\n<div class="controls">} if $self->get_tag('controls_div');
+
+ # start controls div
+ if ( $self->get_tag('controls_div') ) {
+ $output .= qq{\n<div class="controls">};
+ }
+ elsif ( $self->has_element_wrapper_class ) {
+ my $ew_attr = $self->element_wrapper_attributes($result);
+ my $element_wrapper_attrs = process_attrs( $ew_attr );
+ $output .= qq{\n<div$element_wrapper_attrs>};
+ }
+
# the input element itself
$output .= "\n$rendered_widget";
- # end control div
- $output .= "\n</div>" if $self->get_tag('controls_div');
+
+ # close controls div
+ if ( $self->get_tag('controls_div') || $self->has_element_wrapper_class ) {
+ # end control div
+ $output .= "\n</div>";
+ }
+
# the 'after_element'
$output .= $self->get_tag('after_element');
# the error messages
119 t/bootstrap3/basic.t
View
@@ -0,0 +1,119 @@
+use strict;
+use warnings;
+use Test::More;
+use HTML::FormHandler::Test;
+
+use_ok('HTML::FormHandler::Widget::Wrapper::Bootstrap3');
+
+{
+ package MyApp::Form::Test;
+ use HTML::FormHandler::Moose;
+ extends 'HTML::FormHandler';
+
+ has '+widget_wrapper' => ( default => 'Bootstrap3' );
+ has_field 'foo' => ( required => 1 );
+ has_field 'bar';
+ has_field 'active' => ( type => 'Checkbox' );
+ has_field 'vegetables' => ( type => 'Multiple', widget => 'RadioGroup' );
+ sub options_vegetables {
+ return (
+ 1 => 'lettuce',
+ 2 => 'broccoli',
+ 3 => 'carrots',
+ 4 => 'peas',
+ );
+ }
+ has_field 'save' => ( type => 'Submit', element_wrapper_class => ['col-lg-offset-2', 'col-lg-10'] );
+
+}
+
+my $form = MyApp::Form::Test->new;
+ok( $form, 'form builds' );
+
+my $expected = '
+<div class="form-group">
+ <label class="control-label" for="foo">Foo</label>
+ <div>
+ <input class="form-control" id="foo" name="foo" type="text" value="" />
+ </div>
+</div>
+';
+my $rendered = $form->field('foo')->render;
+is_html( $rendered, $expected, 'foo renders ok' );
+
+$expected = '
+<div class="form-group">
+ <div>
+ <div class="checkbox">
+ <label for="active">
+ <input id="active" name="active" type="checkbox" value="1" /> Active
+ </label>
+ </div>
+ </div>
+</div>
+';
+$rendered = $form->field('active')->render;
+is_html( $rendered, $expected, 'checkbox renders ok' );
+
+$expected = '
+<div class="form-group">
+ <div class="col-lg-offset-2 col-lg-10">
+ <input id="save" name="save" type="submit" value="Save" />
+ </div>
+</div>
+';
+$rendered = $form->field('save')->render;
+is_html( $rendered, $expected, 'submit button renders ok' );
+
+$expected = '
+<div class="form-group">
+ <label class="control-label" for="vegetables">Vegetables</label>
+ <div>
+ <div class="radio">
+ <label class="radio" for="vegetables.0">
+ <input id="vegetables.0" name="vegetables" type="radio" value="1" />
+ lettuce
+ </label>
+ </div>
+ <div class="radio">
+ <label class="radio" for="vegetables.1">
+ <input id="vegetables.1" name="vegetables" type="radio" value="2" />
+ broccoli
+ </label>
+ </div>
+ <div class="radio">
+ <label class="radio" for="vegetables.2">
+ <input id="vegetables.2" name="vegetables" type="radio" value="3" />
+ carrots
+ </label>
+ </div>
+ <div class="radio">
+ <label class="radio" for="vegetables.3">
+ <input id="vegetables.3" name="vegetables" type="radio" value="4" />
+ peas
+ </label>
+ </div>
+ </div>
+</div>
+';
+$rendered = $form->field('vegetables')->render;
+is_html( $rendered, $expected, 'radio group renders' );
+
+# after processing
+$form->process( params => { bar => 'bar' } );
+
+$expected = '
+<div class="form-group has-error">
+ <label class="control-label" for="foo">Foo</label>
+ <div>
+ <input class="has-error form-control" id="foo" name="foo" type="text" value="" />
+ <span class="help-block">Foo field is required</span>
+ </div>
+</div>
+';
+$rendered = $form->field('foo')->render;
+is_html( $rendered, $expected, 'foo renders ok with error' );
+
+
+
+done_testing;
2  t/fields/select.t
View
@@ -16,7 +16,7 @@ use HTML::FormHandler::Field::Text;
id => 'f99',
);
has_field 'fruit' => ( type => 'Select' );
- has_field 'vegetables' => ( type => 'Multiple', input_without_param => [], not_nullable => 1 );
+ has_field 'vegetables' => ( type => 'Multiple' );
has_field 'empty' => ( type => 'Multiple', no_option_validation => 1 );
has_field 'build_attr' => ( type => 'Select' );
5 t/render/widget_tags.t
View
@@ -4,6 +4,8 @@ use Test::More;
# this tests that the 'widget_tags'
# works when set on a Form and Field.
+# note: widget_tags in a field have been deprecated for a long time;
+# removing...
{
package MyApp::Old::Form;
use HTML::FormHandler::Moose;
@@ -17,7 +19,7 @@ use Test::More;
);
has_field 'foo';
- has_field 'bar' => ( widget_tags => { field_tag => 1 } );
+ has_field 'bar';
}
my $form = MyApp::Old::Form->new;
@@ -28,7 +30,6 @@ is_deeply( $form->widget_tags, $exp_widget_tags, 'got expected widget tags' );
is( $form->field('foo')->get_tag('my_tag'), 1, 'got widget tag from field' );
my $tags = $form->field('bar')->tags;
my $exp_tags = {
- 'field_tag' => 1,
'my_tag' => 1,
'some_tag' => '<p>Testing, testing...</p>',
};
10 t/render/widgets.t
View
@@ -76,6 +76,7 @@ use HTML::FormHandler::Field::Text;
has_field 'no_render' => ( widget => 'NoRender' );
has_field 'plain' => ( widget_wrapper => 'None' );
has_field 'boxed' => ( widget_wrapper => 'Fieldset', wrapper_attr => { class => 'boxed' } );
+ has_field 'element_wrapper_field' => ( element_wrapper_class => 'large' );
sub html_attributes {
my ( $self, $field, $type, $attr ) = @_;
@@ -240,6 +241,15 @@ is_html( $form->field('boxed')->render,
<input type="text" name="boxed" id="boxed" value="Testing single fieldset" />
</fieldset>', 'fieldset wrapper renders' );
+is_html( $form->field('element_wrapper_field')->render,
+'<div>
+ <label class="label" for="element_wrapper_field">Element wrapper field</label>
+ <div class="large">
+ <input id="element_wrapper_field" name="element_wrapper_field" type="text" value="" />
+ </div>
+</div>',
+ 'element wrapper renders ok' );
+
# table widget
$form = Test::Form->new( widget_form => 'Table', widget_wrapper => 'Table' );
like( $form->render, qr/<table/, 'rendered form contains table' );
Please sign in to comment.
Something went wrong with that request. Please try again.