[libhtml-formhandler-perl] 01/01: [svn-upgrade] Integrating new upstream version, libhtml-formhandler-perl (0.31003)
Damyan Ivanov
dmn at moszumanska.debian.org
Sat Nov 11 23:03:15 UTC 2017
This is an automated email from the git hooks/post-receive script.
dmn pushed a commit to tag upstream/0.31003
in repository libhtml-formhandler-perl.
commit f1343b0ff9708db659098e924b500ecde72ae4a7
Author: Antony Gelberg <antony at wayforth.co.uk>
Date: Mon Jun 7 10:25:52 2010 +0000
[svn-upgrade] Integrating new upstream version, libhtml-formhandler-perl (0.31003)
---
Changes | 11 +++
META.yml | 2 +-
TODO | 9 +--
lib/HTML/FormHandler.pm | 2 +-
lib/HTML/FormHandler/BuildFields.pm | 67 ++++++-----------
lib/HTML/FormHandler/Field.pm | 15 ++--
lib/HTML/FormHandler/Field/Date.pm | 3 +-
lib/HTML/FormHandler/Field/Duration.pm | 4 +-
lib/HTML/FormHandler/Field/Select.pm | 11 ++-
lib/HTML/FormHandler/Field/Text.pm | 4 +-
lib/HTML/FormHandler/I18N/de_de.pm | 47 +++++++++---
lib/HTML/FormHandler/InitResult.pm | 5 +-
lib/HTML/FormHandler/Manual/Intro.pod | 9 ++-
lib/HTML/FormHandler/Manual/Rendering.pod | 14 ++--
lib/HTML/FormHandler/Render/Simple.pm | 6 +-
lib/HTML/FormHandler/Validate.pm | 2 +-
lib/HTML/FormHandler/Widget/ApplyRole.pm | 8 +--
lib/HTML/FormHandler/Widget/Field/Checkbox.pm | 19 ++---
lib/HTML/FormHandler/Widget/Field/CheckboxGroup.pm | 19 ++---
lib/HTML/FormHandler/Widget/Field/Password.pm | 17 ++---
lib/HTML/FormHandler/Widget/Field/RadioGroup.pm | 19 ++---
lib/HTML/FormHandler/Widget/Field/Reset.pm | 7 +-
lib/HTML/FormHandler/Widget/Field/Select.pm | 42 ++++++-----
lib/HTML/FormHandler/Widget/Field/Submit.pm | 7 +-
lib/HTML/FormHandler/Widget/Field/Text.pm | 18 ++---
lib/HTML/FormHandler/Widget/Field/Textarea.pm | 14 ++--
lib/HTML/FormHandler/Widget/Wrapper/Base.pm | 2 +-
lib/HTML/FormHandler/Widget/Wrapper/Simple.pm | 34 +++++----
t/dates.t | 2 +
t/defaults.t | 20 ++++++
t/deflate.t | 26 +++++++
t/filters.t | 2 +
t/render_widgets.t | 84 ++++++++++++++++------
t/xt/custom_fields.t | 26 +++++++
t/xt/init.t | 25 ++++---
t/xt/load_field.t | 3 +
t/xt/locale.t | 2 +-
37 files changed, 402 insertions(+), 205 deletions(-)
diff --git a/Changes b/Changes
index d10b964..dbe39b9 100644
--- a/Changes
+++ b/Changes
@@ -1,3 +1,14 @@
+0.31003 Fri May 7, 2010
+ Change precedence of defaults over item/init_object; add 'default_over_obj' for
+ cases where that behavior is desired.
+ Fix errors in filtering HTML in rendering
+ Call deflation in InitResult::_result_from_obj
+ Split localization of labels into separate 'loc_label' method
+ Call loc_label where label is used in error messages
+ Enable empty strings for wrapper_start and wrapper_end
+ Set locale to en_us where needed in test
+ Fix widget_name_space use in fields
+
0.31002 Wed Apr 21, 2010
Remove unused HTML::Entities from Simple form widget
Move locale test file into xt because of env variable issues in test
diff --git a/META.yml b/META.yml
index 5c1383d..b25fb97 100644
--- a/META.yml
+++ b/META.yml
@@ -39,4 +39,4 @@ requires:
resources:
license: http://dev.perl.org/licenses/
repository: http://github.com/gshank/html-formhandler/tree/master
-version: 0.31002
+version: 0.31003
diff --git a/TODO b/TODO
index fa76b71..c207a76 100644
--- a/TODO
+++ b/TODO
@@ -1,12 +1,7 @@
- result refactoring tasks
- Handle dynamic selection lists in result rendering
- api for result
- put back empty related fields for fif (to allow filling in if empty)
+ Improve TT rendering
+ Refactor messages to set in one place and make translations easier
Unique support for non-top-level fields?
- Create multibox widget & rendering for checkbox group for multiple select
Improve example of Repeatable form (BookDB, User) to do adds & deletes with js
Create more usable 'add_field' routine that will handle ordering, parent,
and form attributes. Use in create_instance.
- add Rendering modules: TT using Data::Section? using HTML::Dom or Treebuilder?, Reaction?
- improve auto field support
investigate a Catalyst View to provide better template support (like Reaction)
diff --git a/lib/HTML/FormHandler.pm b/lib/HTML/FormHandler.pm
index a1d550e..2c62d00 100644
--- a/lib/HTML/FormHandler.pm
+++ b/lib/HTML/FormHandler.pm
@@ -16,7 +16,7 @@ use HTML::FormHandler::Result;
use 5.008;
# always use 5 digits after decimal because of toolchain issues
-our $VERSION = '0.31002';
+our $VERSION = '0.31003';
=head1 NAME
diff --git a/lib/HTML/FormHandler/BuildFields.pm b/lib/HTML/FormHandler/BuildFields.pm
index 744afd8..7d3c15d 100644
--- a/lib/HTML/FormHandler/BuildFields.pm
+++ b/lib/HTML/FormHandler/BuildFields.pm
@@ -199,53 +199,32 @@ sub _make_field {
$field_attr->{name} = $name = $1;
$do_update = 1;
}
-
- my $class;
- if( $type =~ s/^\+// ) {
- # type prefixed with '+', not a built-in
- if( ref $self->field_name_space eq 'ARRAY' ) {
- my $loaded;
- foreach my $ns (@{$self->field_name_space}) {
- $class = $ns . "::" . $type;
- try {
- Class::MOP::load_class($class);
- $loaded++;
- };
- last if $loaded;
- }
- die "Could not load field class '$type' for field '$name'"
- unless $loaded;
- }
- elsif ( $self->field_name_space ) {
- $class = $self->field_name_space . "::" . $type;
- Class::MOP::load_class($class) or
- die "Could not load field class '$class' for field '$name'";
- }
- else {
- $class = $type;
- Class::MOP::load_class($class) or
- die "Could not load field class '$class' for field '$name'";
- }
+ my $field_ns = $self->field_name_space;
+ my @field_name_space = ref $field_ns eq 'ARRAY' ? @$field_ns : $field_ns;
+ my @classes;
+ # '+'-prefixed fields could be full namespaces
+ if ( $type =~ s/^\+// )
+ {
+ push @classes, $type;
}
- else {
- # built-in. look in HTML::FormHandler::Field
- # and HTML::FormHandlerX::Field
- $class = 'HTML::FormHandler::Field::' . $type;
- my @errors;
- try {
- Class::MOP::load_class($class);
- } catch {
- $class = 'HTML::FormHandlerX::Field::' . $type;
- push @errors, $_;
- try {
- Class::MOP::load_class($class);
- } catch {
- push @errors, $_;
- die "Could not load field class '$type' for field '$name'.".
- join("\n[+] ", @errors);
- };
+ foreach my $ns ( @field_name_space, 'HTML::FormHandler::Field', 'HTML::FormHandlerX::Field' )
+ {
+ push @classes, $ns . "::" . $type;
+ }
+ # look for Field in possible namespaces
+ my $loaded;
+ my $class;
+ foreach my $try ( @classes ) {
+ try {
+ Class::MOP::load_class($try);
+ $loaded++;
+ $class = $try;
};
+ last if $loaded;
}
+ die "Could not load field class '$type' for field '$name'"
+ unless $loaded;
+
$field_attr->{form} = $self->form if $self->form;
# parent and name correction for names with dots
diff --git a/lib/HTML/FormHandler/Field.pm b/lib/HTML/FormHandler/Field.pm
index 2b150ba..b8a2c98 100644
--- a/lib/HTML/FormHandler/Field.pm
+++ b/lib/HTML/FormHandler/Field.pm
@@ -569,6 +569,8 @@ has 'input_without_param' => (
has 'not_nullable' => ( is => 'ro', isa => 'Bool' );
has 'init_value' => ( is => 'rw', clearer => 'clear_init_value' );
has 'default' => ( is => 'rw' );
+has 'default_over_obj' => ( is => 'rw', builder => 'build_default_over_obj' );
+sub build_default_over_obj { }
has 'result' => (
isa => 'HTML::FormHandler::Field::Result',
is => 'ro',
@@ -712,7 +714,11 @@ sub build_label {
my $label = $self->name;
$label =~ s/_/ /g;
$label = ucfirst($label);
- return $self->_localize($label);
+ return $label;
+}
+sub loc_label {
+ my $self = shift;
+ return $self->_localize($self->label);
}
has 'title' => ( isa => 'Str', is => 'rw' );
has 'style' => ( isa => 'Str', is => 'rw' );
@@ -897,6 +903,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;
# widgets will already have been applied by BuildFields, but this allows
# testing individual fields
$self->apply_rendering_widgets unless ($self->can('render') );
@@ -911,6 +918,9 @@ sub _result_from_fields {
my ( $self, $result ) = @_;
if ( my @values = $self->get_default_value ) {
+ if ( $self->_can_deflate ) {
+ @values = $self->_apply_deflation(@values);
+ }
my $value = @values > 1 ? \@values : shift @values;
$self->init_value($value) if defined $value;
$result->_set_value($value) if defined $value;
@@ -1076,9 +1086,6 @@ sub dump {
sub apply_rendering_widgets {
my $self = shift;
- if( $self->form ) {
- $self->add_widget_name_space( @{$self->form->widget_name_space} );
- }
if ( $self->widget ) {
$self->apply_widget_role( $self, $self->widget, 'Field' );
}
diff --git a/lib/HTML/FormHandler/Field/Date.pm b/lib/HTML/FormHandler/Field/Date.pm
index 7dd50d7..ad1d786 100644
--- a/lib/HTML/FormHandler/Field/Date.pm
+++ b/lib/HTML/FormHandler/Field/Date.pm
@@ -74,7 +74,8 @@ sub deflate {
my ( $self, $value ) = @_;
$value ||= $self->value;
- return unless ref $value eq 'DateTime';
+ # if not a DateTime, assume correctly formated string and return
+ return $value unless ref $value eq 'DateTime';
my $format = $self->get_strf_format;
my $string = $value->strftime($format);
return $string;
diff --git a/lib/HTML/FormHandler/Field/Duration.pm b/lib/HTML/FormHandler/Field/Duration.pm
index 991ddce..4be2953 100644
--- a/lib/HTML/FormHandler/Field/Duration.pm
+++ b/lib/HTML/FormHandler/Field/Duration.pm
@@ -18,7 +18,7 @@ Subfield names:
For example:
- has 'duration' => ( type => 'Compound' );
+ has 'duration' => ( type => 'Duration' );
has 'duration.hours' => ( type => 'Int', range_start => 0,
range_end => 23 );
has 'duration.minutes' => ( type => 'Int', range_start => 0,
@@ -33,7 +33,7 @@ sub validate {
my @dur_parms;
foreach my $child ( $self->all_fields ) {
unless ( $child->value =~ /^\d+$/ ) {
- $self->add_error( "Invalid value for " . $self->label . " " . $child->label );
+ $self->add_error( "Invalid value for [1_] [2_]", $self->loc_label, $child->loc_label );
next;
}
push @dur_parms, ( $child->accessor => $child->value );
diff --git a/lib/HTML/FormHandler/Field/Select.pm b/lib/HTML/FormHandler/Field/Select.pm
index 06bdde9..dfe05e2 100644
--- a/lib/HTML/FormHandler/Field/Select.pm
+++ b/lib/HTML/FormHandler/Field/Select.pm
@@ -30,6 +30,10 @@ In a field declaration:
In a custom field class:
+ package MyApp::Field::WeekDay;
+ use Moose;
+ extends 'HTML::FormHandler::Field::Select';
+ ....
sub build_options {
my $i = 0;
my @days = ('Sunday', 'Monday', 'Tuesday', 'Wednesday',
@@ -43,6 +47,7 @@ In a custom field class:
In a form:
+ has_field 'fruit' => ( type => 'Select' );
sub options_fruit {
return (
1 => 'apples',
@@ -50,7 +55,11 @@ In a form:
3 => 'kiwi',
);
}
-
+ -- or --
+ has 'options_fruit' => ( is => 'rw', traits => ['Array'],
+ default => sub { [1 => 'apples', 2 => 'oranges',
+ 3 => 'kiwi'] } );
+
Notice that, as a convenience, you can return a simple array (or arrayref)
for the options array in the 'options_field_name' method. The hashrefs with
'value' and 'label' keys will be constructed for you by FormHandler. The
diff --git a/lib/HTML/FormHandler/Field/Text.pm b/lib/HTML/FormHandler/Field/Text.pm
index 793d01e..0635198 100644
--- a/lib/HTML/FormHandler/Field/Text.pm
+++ b/lib/HTML/FormHandler/Field/Text.pm
@@ -39,7 +39,7 @@ sub validate {
# Check for max length
if ( my $maxlength = $field->maxlength ) {
return $field->add_error( $field->maxlength_message,
- $maxlength, length $value, $field->label )
+ $maxlength, length $value, $field->loc_label )
if length $value > $maxlength;
}
@@ -47,7 +47,7 @@ sub validate {
if ( my $minlength = $field->minlength || $field->_min_length_r ) {
return $field->add_error(
$field->minlength_message,
- $minlength, length $value, $field->label )
+ $minlength, length $value, $field->loc_label )
if length $value < $minlength;
}
return 1;
diff --git a/lib/HTML/FormHandler/I18N/de_de.pm b/lib/HTML/FormHandler/I18N/de_de.pm
index 2e7f8c4..6830ba1 100644
--- a/lib/HTML/FormHandler/I18N/de_de.pm
+++ b/lib/HTML/FormHandler/I18N/de_de.pm
@@ -8,29 +8,51 @@ use utf8;
# Auto define lexicon
our %Lexicon = (
'_AUTO' => 1,
-
+
+ # H::F::Field::Date
+ 'Date is too early' => 'Datum ist zu früh',
+ 'Date is too late' => 'Datum ist zu spät',
+
+ # H::F::Field::DateTime
+ 'Not a valid DateTime' => 'Ungültige Datums-/Zeitangabe',
+
# H::F::Field::Email
'Email should be of the format [_1]' => 'E-Mail sollte die Form [_1] haben',
-
+
# H::F::Field::Integer
'Value must be an integer' => 'Muss eine positive ganze Zahl sein',
-
+
# H::F::Field::Money
'Value cannot be converted to money' => 'Wert kann nicht in Betrag konvertiert werden',
'Value must be a real number' => 'Muss eine Dezimalzahl sein',
-
+
# H::F::Field::Password
'Please enter a password in this field' => 'Bitte ein Passwort eingeben',
-
+
# H::F::Field::PasswordConf
'Please enter a password confirmation' => 'Bitte das Passwort bestätigen',
-
+
# H::F::Field::PosInteger
'Value must be a positive integer' => 'Muss eine positive ganze Zahl sein',
-
+
+ # H::F::Field::Select
+ 'This field does not take multiple values' => 'Mehrfachauswahl nicht erlaubt',
+
+ # H::F::Field::Text
+ 'Please limit to [quant,_1,character]. You submitted [_2]' => 'Bitte auf [_1] Zeichen beschränken. Sie haben [_2] eingegeben',
+ 'Input must be at least [quant,_1,character]. You submitted [_2]' => 'Eingabe muss mindestens [_1] Zeichen lang sein. Sie haben nur [_2] eingegeben',
+
+ # H::F::Field::Upload
+ 'File uploaded is empty' => 'Hochgeladene Datei ist leer',
+ 'File is too small (< [_1] bytes)' => 'Datei ist zu klein (< [_1] bytes)',
+ 'File is too big (> [_1] bytes)' => 'Datei ist zu groß (> [_1] bytes)',
+
# H::F::Field
'field is invalid' => 'Feld ist ungültig',
+ # H::F::Model
+ 'Value must be unique in the database' => 'Wert existiert bereits in der Datenbank',
+
# H::F::Types
'Must be a positive number' => 'Muss eine positive Zahl sein',
'Must be a positive integer' => 'Muss eine positive ganze Zahl sein',
@@ -52,8 +74,15 @@ our %Lexicon = (
# H::F::Validate::Actions
'Wrong value' => 'Ungültiger Wert',
- ### not translatable: '"$value" does not match' => '',
- ### not translatable: '"$value" not allowed' => '',
+ '[_1] does not match' => '[_1] ist kein gültiger Wert',
+ '[_1] not allowed' => '[_1] ist nicht erlaubt',
+ 'error occurred' => 'Fehler aufgetreten',
+
+ # H::F::Validate
+ 'value must be between [_1] and [_2]' => 'Wert muss zwischen [_1] und [_2] liegen',
+ 'value must be greater than or equal to [_1]' => 'Wert muss größer oder gleich [_1] sein',
+ 'value must be less than or equal to [_1]' => 'Wert muss kleiner oder gleich [_1] sein',
+
);
1;
diff --git a/lib/HTML/FormHandler/InitResult.pm b/lib/HTML/FormHandler/InitResult.pm
index 09484bf..f166a96 100644
--- a/lib/HTML/FormHandler/InitResult.pm
+++ b/lib/HTML/FormHandler/InitResult.pm
@@ -102,7 +102,8 @@ sub _get_value {
my $accessor = $field->accessor;
my @values;
- if ( @values = $field->get_default_value ) {
+ if( defined $field->default_over_obj ) {
+ @values = $field->default_over_obj;
}
elsif ( blessed($item) && $item->can($accessor) ) {
@values = $item->$accessor;
@@ -110,6 +111,8 @@ sub _get_value {
elsif ( exists $item->{$accessor} ) {
@values = $item->{$accessor};
}
+ elsif ( @values = $field->get_default_value ) {
+ }
else {
return;
}
diff --git a/lib/HTML/FormHandler/Manual/Intro.pod b/lib/HTML/FormHandler/Manual/Intro.pod
index 75896c3..85e9f5f 100644
--- a/lib/HTML/FormHandler/Manual/Intro.pod
+++ b/lib/HTML/FormHandler/Manual/Intro.pod
@@ -528,13 +528,18 @@ Field errors are in C<< $field->errors >>.
The fields are assumed to be in the HTML::FormHandler::Field name
space. If you want to explicitly list the field's package, prefix it
-with a plus sign. The field name space for "+" prefixed fields can
-be set with the form's "field_name_space" attribute:
+with a plus sign. The field_name_space plus the default name spaces
+'HTML::FormHandler::Field' and 'HTML::FormHandlerX::Field' will be
+searched for fields.
has '+field_name_space' => ( default => 'MyApp::Form::Field' );
has_field 'name' => ( type => 'Text' ); # HTML::FormHandler::Field::Text
+ has_field 'name' => ( type => '+My::FieldType' ); # My::Fieldtype
has_field 'foo' => ( type => +Foo' ); # MyApp::Form::Field::Foo
+ or
+ has_field 'foo' => ( type => 'Foo' ); # MyApp::Form::Field::Foo
+
The most basic type is "Text", which takes a single scalar value. (If the
type of a field is not specified, it will be set to 'Text'.) A "Select"
diff --git a/lib/HTML/FormHandler/Manual/Rendering.pod b/lib/HTML/FormHandler/Manual/Rendering.pod
index 7643e7d..8ffc878 100644
--- a/lib/HTML/FormHandler/Manual/Rendering.pod
+++ b/lib/HTML/FormHandler/Manual/Rendering.pod
@@ -96,7 +96,7 @@ and Table). The form widget is specified in the form with 'widget_form'.
package MyApp::Form;
....
- has '+widget_form' => ( widget_form => 'Simple' );
+ has '+widget_form' => ( default => 'Simple' );
...
The 'wrapper' for field rendering can also be specified with 'widget_wrapper'.
@@ -108,12 +108,15 @@ You can specify a wrapper class for all the fields in the form by setting
'widget_wrapper' in the form class, or you can set them individually by setting
'widget_wrapper' on individual fields.
- has 'some_field' => ( widget_wrapper => 'MyWrapper' );
+ has_field 'some_field' => ( widget_wrapper => 'MyWrapper' );
The 'widget' attribute is set to a default in FormHandler fields, or you can
set it to a different widget in your field declarations.
- has 'another_field' => ( widget => 'MyWidget', widget_wrapper => 'MyWrapper' );
+ has_field 'another_field' => (
+ widget => 'MyWidget',
+ widget_wrapper => 'MyWrapper'
+ );
Can be set in the form:
@@ -134,7 +137,10 @@ By default, a form will use the Form::Simple and Wrapper::Simple widgets. If you
want to use the table format you can change the 'widget_form' and 'widget_wrapper'
attributes in the form, or do it on new:
- my $form = MyApp::Form->new( widget_form => 'Table', widget_wrapper => 'Table' );
+ my $form = MyApp::Form->new(
+ widget_form => 'Table',
+ widget_wrapper => 'Table'
+ );
=head2 Rendering filter for fill-in-form values
diff --git a/lib/HTML/FormHandler/Render/Simple.pm b/lib/HTML/FormHandler/Render/Simple.pm
index 004ca92..6bc9298 100644
--- a/lib/HTML/FormHandler/Render/Simple.pm
+++ b/lib/HTML/FormHandler/Render/Simple.pm
@@ -214,7 +214,7 @@ sub render_field_struct {
}
elsif ( $l_type eq 'legend' ) {
$output .= '<fieldset class="' . $field->html_name . '">';
- $output .= '<legend>' . $field->html_filter($field->label) . '</legend>';
+ $output .= '<legend>' . $field->html_filter($field->loc_label) . '</legend>';
}
$output .= $rendered_field;
foreach my $error ($field->all_errors){
@@ -368,7 +368,7 @@ sub render_upload {
sub _label {
my ( $self, $field ) = @_;
return '<label class="label" for="' . $field->id . '">' .
- $field->html_filter($field->label)
+ $field->html_filter($field->loc_label)
. ': </label>';
}
@@ -389,7 +389,7 @@ sub render_submit {
$output .= $field->html_name . '"';
$output .= ' id="' . $field->id . '"';
$output .= $self->_add_html_attributes( $field );
- $output .= ' value="' . $field->html_filter($field->value) . '" />';
+ $output .= ' value="' . $field->html_filter($field->_localize($field->value)) . '" />';
return $output;
}
diff --git a/lib/HTML/FormHandler/Validate.pm b/lib/HTML/FormHandler/Validate.pm
index f638cd9..eabe4fa 100644
--- a/lib/HTML/FormHandler/Validate.pm
+++ b/lib/HTML/FormHandler/Validate.pm
@@ -20,7 +20,7 @@ has 'required_message' => (
is => 'rw',
lazy => 1,
default => sub {
- return [ '[_1] field is required', shift->label ];
+ return [ '[_1] field is required', shift->loc_label ];
}
);
has 'unique' => ( isa => 'Bool', is => 'rw', predicate => 'has_unique' );
diff --git a/lib/HTML/FormHandler/Widget/ApplyRole.pm b/lib/HTML/FormHandler/Widget/ApplyRole.pm
index 20718c3..4677928 100644
--- a/lib/HTML/FormHandler/Widget/ApplyRole.pm
+++ b/lib/HTML/FormHandler/Widget/ApplyRole.pm
@@ -3,6 +3,7 @@ package HTML::FormHandler::Widget::ApplyRole;
use Moose::Role;
use File::Spec;
use Class::MOP;
+use Try::Tiny;
our $ERROR;
@@ -21,11 +22,10 @@ sub get_widget_role {
('HTML::FormHandler::Widget', 'HTML::FormHandlerX::Widget') );
foreach my $ns (@name_spaces) {
my $render_role = $ns . $ldir . $widget_class;
- if ( eval { Class::MOP::load_class($render_role) } ) {
- return $render_role;
- }
+ try { Class::MOP::load_class($render_role) } catch { die $_ unless $_ =~ /^Can't locate/; };
+ return $render_role if Class::MOP::is_class_loaded($render_role);
}
- die "not able to load $dir widget $widget_class from " . join(", ", @name_spaces);
+ die "Can't find $dir widget $widget_class from " . join(", ", @name_spaces);
}
# this is for compatibility with widget names like 'radio_group'
diff --git a/lib/HTML/FormHandler/Widget/Field/Checkbox.pm b/lib/HTML/FormHandler/Widget/Field/Checkbox.pm
index 59fd58a..ce323a9 100644
--- a/lib/HTML/FormHandler/Widget/Field/Checkbox.pm
+++ b/lib/HTML/FormHandler/Widget/Field/Checkbox.pm
@@ -1,21 +1,24 @@
package HTML::FormHandler::Widget::Field::Checkbox;
use Moose::Role;
+use namespace::autoclean;
+
with 'HTML::FormHandler::Widget::Field::Role::HTMLAttributes';
sub render {
- my ( $self, $result ) = @_;
+ my $self = shift;
+ my $result = shift || $self->result;
+ my $checkbox_value = $self->checkbox_value;
- $result ||= $self->result;
- my $fif = $result->fif;
- my $output = '<input type="checkbox" name="';
- $output .= $self->html_name . '" id="' . $self->id . '"';
- $output .= ' value="' . $self->html_filter($self->checkbox_value) . '"';
- $output .= ' checked="checked"' if $fif eq $self->checkbox_value;
+ my $output = '<input type="checkbox" name="'
+ . $self->html_name . '" id="' . $self->id . '" value="'
+ . $self->html_filter($checkbox_value) . '"';
+ $output .= ' checked="checked"'
+ if $result->fif eq $checkbox_value;
$output .= $self->_add_html_attributes;
$output .= ' />';
+
return $self->wrap_field( $result, $output );
}
-use namespace::autoclean;
1;
diff --git a/lib/HTML/FormHandler/Widget/Field/CheckboxGroup.pm b/lib/HTML/FormHandler/Widget/Field/CheckboxGroup.pm
index 5824548..b7aca47 100644
--- a/lib/HTML/FormHandler/Widget/Field/CheckboxGroup.pm
+++ b/lib/HTML/FormHandler/Widget/Field/CheckboxGroup.pm
@@ -1,6 +1,7 @@
package HTML::FormHandler::Widget::Field::CheckboxGroup;
use Moose::Role;
+use namespace::autoclean;
with 'HTML::FormHandler::Widget::Field::Role::SelectedOption';
with 'HTML::FormHandler::Widget::Field::Role::HTMLAttributes';
@@ -9,14 +10,17 @@ has 'input_without_param' => ( is => 'ro', default => sub {[]} );
has 'not_nullable' => ( is => 'ro', default => 1 );
sub render {
- my ( $self, $result ) = @_;
-
- $result ||= $self->result;
+ my $self = shift;
+ my $result = shift || $self->result;
my $output = " <br />";
my $index = 0;
+ my $id = $self->id;
+ my $html_attributes = $self->_add_html_attributes; # does that make sense?
+
foreach my $option ( @{ $self->options } ) {
- $output .= '<input type="checkbox" value="' . $option->{value} . '"';
- $output .= ' name="' . $self->html_name . '" id="' . $self->id . ".$index\"";
+ $output .= '<input type="checkbox" value="'
+ . $self->html_filter($option->{value}) . '" name="'
+ . $self->html_name . qq{" id="$id.$index"};
if ( my $ffif = $result->fif ) {
if ( $self->multiple == 1 ) {
my @fif;
@@ -38,13 +42,12 @@ sub render {
}
$output .= ' checked="checked"'
if $self->check_selected_option($option);
- $output .= $self->_add_html_attributes;
+ $output .= $html_attributes;
$output .= ' />';
- $output .= $option->{label} . '<br />';
+ $output .= $self->html_filter($option->{label}) . '<br />';
$index++;
}
return $self->wrap_field( $result, $output );
}
-use namespace::autoclean;
1;
diff --git a/lib/HTML/FormHandler/Widget/Field/Password.pm b/lib/HTML/FormHandler/Widget/Field/Password.pm
index 47fdce6..4d8d7d0 100644
--- a/lib/HTML/FormHandler/Widget/Field/Password.pm
+++ b/lib/HTML/FormHandler/Widget/Field/Password.pm
@@ -1,22 +1,23 @@
package HTML::FormHandler::Widget::Field::Password;
use Moose::Role;
+use namespace::autoclean;
+
with 'HTML::FormHandler::Widget::Field::Role::HTMLAttributes';
sub render {
- my ( $self, $result ) = @_;
+ my $self = shift;
+ my $result = shift || $self->result;
+ my $t;
- $result ||= $self->result;
- my $output = '<input type="password" name="';
- $output .= $self->html_name . '"';
- $output .= ' id="' . $self->id . '"';
- $output .= ' size="' . $self->size . '"' if $self->size;
- $output .= ' maxlength="' . $self->maxlength . '"' if $self->maxlength;
+ my $output = '<input type="password" name="'
+ . $self->html_name . '" id="' . $self->id . '"';
+ $output .= qq{ size="$t"} if $t = $self->size;
+ $output .= qq{ maxlength="$t"} if $t = $self->maxlength;
$output .= ' value="' . $self->html_filter($result->fif) . '"';
$output .= $self->_add_html_attributes;
$output .= ' />';
return $self->wrap_field( $result, $output );
}
-use namespace::autoclean;
1;
diff --git a/lib/HTML/FormHandler/Widget/Field/RadioGroup.pm b/lib/HTML/FormHandler/Widget/Field/RadioGroup.pm
index 8f2b274..d5958a1 100644
--- a/lib/HTML/FormHandler/Widget/Field/RadioGroup.pm
+++ b/lib/HTML/FormHandler/Widget/Field/RadioGroup.pm
@@ -1,25 +1,28 @@
package HTML::FormHandler::Widget::Field::RadioGroup;
use Moose::Role;
+use namespace::autoclean;
with 'HTML::FormHandler::Widget::Field::Role::SelectedOption';
sub render {
- my ( $self, $result ) = @_;
-
- $result ||= $self->result;
+ my $self = shift;
+ my $result = shift || $self->result;
+ my $id = $self->id;
my $output = " <br />";
my $index = 0;
+
foreach my $option ( @{ $self->options } ) {
- $output .= '<input type="radio" value="' . $option->{value} . '"';
- $output .= ' name="' . $self->html_name . '" id="' . $self->id . ".$index\"";
- $output .= ' checked="checked"' if $self->check_selected_option($option, $result->fif);
+ $output .= '<input type="radio" value="'
+ . $self->html_filter($option->{value}) . '" name="'
+ . $self->html_name . qq{" id="$id.$index"};
+ $output .= ' checked="checked"'
+ if $self->check_selected_option($option, $result->fif);
$output .= ' />';
- $output .= $option->{label} . '<br />';
+ $output .= $self->html_filter($option->{label}) . '<br />';
$index++;
}
return $self->wrap_field( $result, $output );
}
-use namespace::autoclean;
1;
diff --git a/lib/HTML/FormHandler/Widget/Field/Reset.pm b/lib/HTML/FormHandler/Widget/Field/Reset.pm
index 77fe3e9..50c3c00 100644
--- a/lib/HTML/FormHandler/Widget/Field/Reset.pm
+++ b/lib/HTML/FormHandler/Widget/Field/Reset.pm
@@ -1,9 +1,11 @@
package HTML::FormHandler::Widget::Field::Reset;
use Moose::Role;
+use namespace::autoclean;
+
with 'HTML::FormHandler::Widget::Field::Role::HTMLAttributes';
-has 'no_render_label' => ( is => 'ro', lazy => 1, default => 1 );
+has 'no_render_label' => ( is => 'ro', isa => 'Bool', default => 1 );
sub render {
my ( $self, $result ) = @_;
@@ -12,11 +14,10 @@ sub render {
my $output = '<input type="reset" name="';
$output .= $self->html_name . '"';
$output .= ' id="' . $self->id . '"';
- $output .= ' value="' . $self->value . '"';
+ $output .= ' value="' . $self->html_filter($self->value) . '"';
$output .= $self->_add_html_attributes;
$output .= ' />';
return $self->wrap_field( $result, $output );
}
-use namespace::autoclean;
1;
diff --git a/lib/HTML/FormHandler/Widget/Field/Select.pm b/lib/HTML/FormHandler/Widget/Field/Select.pm
index f850a4a..c3c5f2c 100644
--- a/lib/HTML/FormHandler/Widget/Field/Select.pm
+++ b/lib/HTML/FormHandler/Widget/Field/Select.pm
@@ -1,29 +1,34 @@
package HTML::FormHandler::Widget::Field::Select;
use Moose::Role;
+use namespace::autoclean;
with 'HTML::FormHandler::Widget::Field::Role::SelectedOption';
with 'HTML::FormHandler::Widget::Field::Role::HTMLAttributes';
sub render {
- my ( $self, $result ) = @_;
+ my $self = shift;
+ my $result = shift || $self->result;
+ my $id = $self->id;
+ my $index = 0;
+ my $multiple = $self->multiple;
+ my $output = '<select name="' . $self->html_name . qq{" id="$id"};
+ my $t;
- $result ||= $self->result;
- my $output = '<select name="' . $self->html_name . '"';
- $output .= ' id="' . $self->id . '"';
- $output .= ' multiple="multiple"' if $self->multiple == 1;
- $output .= ' size="' . $self->size . '"' if $self->size;
+ $output .= ' multiple="multiple"' if $multiple;
+ $output .= qq{ size="$t"} if $t = $self->size;
$output .= $self->_add_html_attributes;
$output .= '>';
- my $index = 0;
- if( $self->empty_select ) {
- $output .= '<option value="">' . $self->empty_select . '</option>';
- }
+
+ $t = $self->empty_select
+ and $output .= qq{<option value="">$t</option>};
+
foreach my $option ( @{ $self->{options} } ) {
- $output .= '<option value="' . $option->{value} . '" ';
- $output .= 'id="' . $self->id . ".$index\" ";
- if ( my $ffif = $self->html_filter($result->fif) ) {
- if ( $self->multiple == 1 ) {
+ $output .= '<option value="'
+ . $self->html_filter($option->{value})
+ . qq{" id="$id.$index"};
+ if ( my $ffif = $result->fif ) {
+ if ( $multiple ) {
my @fif;
if ( ref $ffif ) {
@fif = @{$ffif};
@@ -32,23 +37,22 @@ sub render {
@fif = ($ffif);
}
foreach my $optval (@fif) {
- $output .= 'selected="selected"'
+ $output .= ' selected="selected"'
if $self->check_selected_option($option, $optval);
}
}
else {
- $output .= 'selected="selected"'
+ $output .= ' selected="selected"'
if $self->check_selected_option($option, $ffif);
}
}
- $output .= 'selected="selected"'
+ $output .= ' selected="selected"'
if $self->check_selected_option($option);
- $output .= '>' . $option->{label} . '</option>';
+ $output .= '>' . $self->html_filter($option->{label}) . '</option>';
$index++;
}
$output .= '</select>';
return $self->wrap_field( $result, $output );
}
-use namespace::autoclean;
1;
diff --git a/lib/HTML/FormHandler/Widget/Field/Submit.pm b/lib/HTML/FormHandler/Widget/Field/Submit.pm
index 5d25a8f..e7be064 100644
--- a/lib/HTML/FormHandler/Widget/Field/Submit.pm
+++ b/lib/HTML/FormHandler/Widget/Field/Submit.pm
@@ -1,9 +1,11 @@
package HTML::FormHandler::Widget::Field::Submit;
use Moose::Role;
+use namespace::autoclean;
+
with 'HTML::FormHandler::Widget::Field::Role::HTMLAttributes';
-has 'no_render_label' => ( is => 'ro', lazy => 1, default => 1 );
+has 'no_render_label' => ( is => 'ro', isa => 'Bool', default => 1 );
sub render {
my ( $self, $result ) = @_;
@@ -12,11 +14,10 @@ sub render {
my $output = '<input type="submit" name="';
$output .= $self->html_name . '"';
$output .= ' id="' . $self->id . '"';
- $output .= ' value="' . $self->value . '"';
+ $output .= ' value="' . $self->html_filter($self->_localize($self->value)) . '"';
$output .= $self->_add_html_attributes;
$output .= ' />';
return $self->wrap_field( $result, $output );
}
-use namespace::autoclean;
1;
diff --git a/lib/HTML/FormHandler/Widget/Field/Text.pm b/lib/HTML/FormHandler/Widget/Field/Text.pm
index 6dd8d0d..770054f 100644
--- a/lib/HTML/FormHandler/Widget/Field/Text.pm
+++ b/lib/HTML/FormHandler/Widget/Field/Text.pm
@@ -1,22 +1,24 @@
package HTML::FormHandler::Widget::Field::Text;
use Moose::Role;
+use namespace::autoclean;
+
with 'HTML::FormHandler::Widget::Field::Role::HTMLAttributes';
sub render {
- my ( $self, $result ) = @_;
+ my $self = shift;
+ my $result = shift || $self->result;
+ my $t;
- $result ||= $self->result;
- my $output = '<input type="text" name="';
- $output .= $self->html_name . '"';
- $output .= ' id="' . $self->id . '"';
- $output .= ' size="' . $self->size . '"' if $self->size;
- $output .= ' maxlength="' . $self->maxlength . '"' if $self->maxlength;
+ my $output = '<input type="text" name="'
+ . $self->html_name . '" id="' . $self->id . '"';
+ $output .= qq{ size="$t"} if $t = $self->size;
+ $output .= qq{ maxlength="$t"} if $t = $self->maxlength;
$output .= ' value="' . $self->html_filter($result->fif) . '"';
$output .= $self->_add_html_attributes;
$output .= ' />';
+
return $self->wrap_field( $result, $output );
}
-use namespace::autoclean;
1;
diff --git a/lib/HTML/FormHandler/Widget/Field/Textarea.pm b/lib/HTML/FormHandler/Widget/Field/Textarea.pm
index 0d0b20f..fa443ec 100644
--- a/lib/HTML/FormHandler/Widget/Field/Textarea.pm
+++ b/lib/HTML/FormHandler/Widget/Field/Textarea.pm
@@ -1,12 +1,13 @@
package HTML::FormHandler::Widget::Field::Textarea;
use Moose::Role;
+use namespace::autoclean;
+
with 'HTML::FormHandler::Widget::Field::Role::HTMLAttributes';
sub render {
- my ( $self, $result ) = @_;
-
- $result ||= $self->result;
+ my $self = shift;
+ my $result = shift || $self->result;
my $fif = $self->html_filter($result->fif) || '';
my $id = $self->id;
my $cols = $self->cols || 10;
@@ -14,14 +15,11 @@ sub render {
my $name = $self->html_name;
my $output =
- qq(<textarea name="$name" id="$id" )
+ qq(<textarea name="$name" id="$id")
. $self->_add_html_attributes
- . qq(rows="$rows" cols="$cols">)
- . $self->html_filter($fif)
- . q(</textarea>);
+ . qq( rows="$rows" cols="$cols">$fif</textarea>);
return $self->wrap_field( $result, $output );
}
-use namespace::autoclean;
1;
diff --git a/lib/HTML/FormHandler/Widget/Wrapper/Base.pm b/lib/HTML/FormHandler/Widget/Wrapper/Base.pm
index ea0700a..f79909b 100644
--- a/lib/HTML/FormHandler/Widget/Wrapper/Base.pm
+++ b/lib/HTML/FormHandler/Widget/Wrapper/Base.pm
@@ -4,7 +4,7 @@ use Moose::Role;
sub render_label {
my $self = shift;
- return '<label class="label" for="' . $self->id . '">' . $self->label . ': </label>';
+ return '<label class="label" for="' . $self->id . '">' . $self->loc_label . ': </label>';
}
sub render_class {
diff --git a/lib/HTML/FormHandler/Widget/Wrapper/Simple.pm b/lib/HTML/FormHandler/Widget/Wrapper/Simple.pm
index 0d3c453..49a3670 100644
--- a/lib/HTML/FormHandler/Widget/Wrapper/Simple.pm
+++ b/lib/HTML/FormHandler/Widget/Wrapper/Simple.pm
@@ -1,6 +1,8 @@
package HTML::FormHandler::Widget::Wrapper::Simple;
use Moose::Role;
+use namespace::autoclean;
+
with 'HTML::FormHandler::Widget::Wrapper::Base';
=head1 NAME
@@ -27,27 +29,33 @@ in paragraph tags instead:
sub wrap_field {
my ( $self, $result, $rendered_widget ) = @_;
-
- my $start_tag = $self->get_tag('wrapper_start') || '<div<%class%>>';
+ my $t;
+ my $start_tag = defined($t = $self->get_tag('wrapper_start')) ?
+ $t : '<div<%class%>>';
+ my $is_compound = $self->has_flag('is_compound');
my $class = $self->render_class($result);
+ my $output = "\n";
+
$start_tag =~ s/<%class%>/$class/g;
- my $output = "\n" . $start_tag;
- if ( $self->has_flag('is_compound') ) {
+ $output .= $start_tag;
+
+ if ( $is_compound ) {
$output .= '<fieldset class="' . $self->html_name . '">';
- $output .= '<legend>' . $self->label . '</legend>';
+ $output .= '<legend>' . $self->loc_label . '</legend>';
}
elsif ( !$self->has_flag('no_render_label') && $self->label ) {
$output .= $self->render_label;
}
+
$output .= $rendered_widget;
- $output .= qq{\n<span class="error_message">$_</span>} for $result->all_errors;
- if ( $self->has_flag('is_compound') ) {
- $output .= '</fieldset>';
- }
- my $end_tag = $self->get_tag('wrapper_end') || '</div>';
- $output .= $end_tag . "\n";
- return $output;
+ $output .= qq{\n<span class="error_message">$_</span>}
+ for $result->all_errors;
+ $output .= '</fieldset>'
+ if $is_compound;
+
+ $output .= defined($t = $self->get_tag('wrapper_end')) ? $t : '</div>';
+
+ return "$output\n";
}
-no Moose::Role;
1;
diff --git a/t/dates.t b/t/dates.t
index 362d854..77f7e03 100644
--- a/t/dates.t
+++ b/t/dates.t
@@ -8,6 +8,8 @@ BEGIN {
plan skip_all => 'DateTime::Format::Strptime required' if $@;
}
+$ENV{LANG} = 'en_us'; # in case user has LANG set
+
#
# DateMDY
#
diff --git a/t/defaults.t b/t/defaults.t
index ff3735f..740b29b 100644
--- a/t/defaults.t
+++ b/t/defaults.t
@@ -102,4 +102,24 @@ $form = Test::Form->new;
is( $form->field('foo')->value, 'some_quux', 'field initialized by init_object' );
+{
+ package Mock::Object;
+ use Moose;
+ has 'meow' => ( is => 'rw' );
+}
+{
+ package Test::Object;
+ use HTML::FormHandler::Moose;
+ extends 'HTML::FormHandler';
+ with 'HTML::FormHandler::Model::Object';
+ has_field 'meow' => ( default => 'this_should_get_overridden' );
+
+}
+
+$obj = Mock::Object->new( meow => 'the_real_meow' );
+
+$form = Test::Object->new;
+$form->process( item => $obj, item_id => 1, params => {} );
+is( $form->field('meow')->value, 'the_real_meow', 'defaults should not override actual item values');
+
done_testing;
diff --git a/t/deflate.t b/t/deflate.t
index 4f3cc51..59800fc 100644
--- a/t/deflate.t
+++ b/t/deflate.t
@@ -48,4 +48,30 @@ is_deeply( $form->value, { bar => 'aabbcc', foo => 'one-x-two-xx-three-xxx' }, '
is( $form->field('foo.one')->fif, 'x', 'correct fif' );
is( $form->field('foo')->value, 'one-x-two-xx-three-xxx', 'right value for foo field' );
+{
+ package Test::Deflate;
+ use HTML::FormHandler::Moose;
+ extends 'HTML::FormHandler';
+
+ has_field 'foo' => (
+ default => 'deflate me!',
+ deflation => sub {
+ my ( $value ) = @_;
+
+ if ( $value eq 'deflate me!' ) {
+ return 'deflated value';
+ } else {
+ return 'unexpected value';
+ }
+ }
+ );
+
+}
+
+$form = Test::Deflate->new;
+ok( $form, 'form builds' );
+
+is( $form->field('foo')->value, 'deflated value', 'default values should be deflated too' );
+
+
done_testing;
diff --git a/t/filters.t b/t/filters.t
index 52ae616..605bbed 100644
--- a/t/filters.t
+++ b/t/filters.t
@@ -7,6 +7,8 @@ use lib 't/lib';
use DateTime;
use Scalar::Util qw(blessed);
+$ENV{LANG} = 'en_us'; # in case user has LANG set
+
{
package My::Form;
use HTML::FormHandler::Moose;
diff --git a/t/render_widgets.t b/t/render_widgets.t
index 574edf0..4638c1b 100644
--- a/t/render_widgets.t
+++ b/t/render_widgets.t
@@ -27,16 +27,25 @@ use HTML::FormHandler::Field::Text;
widget => 'radio_group',
options => [
{
- value => 0,
- label => 'No',
+ value => 'no & never',
+ label => 'No & Never',
# this can depend on something else,
# with fixed value will cause field be
# always checked even after process
checked => 1,
},
- { value => 1, label => 'Yes' },
+ { value => '"yes"', label => 'Yes' },
]
);
+ has_field 'comedians' => (
+ type => 'Multiple',
+ widget => 'checkbox_group',
+ options => [
+ { value => 'keaton', label => 'Buster Keaton'},
+ { value => 'chaplin', label => 'Charly Chaplin'},
+ { value => 'laurel & hardy', label => 'Stan Laurel & Oliver Hardy' },
+ ],
+ );
has_field 'active' => ( type => 'Checkbox' );
has_field 'comments' => ( type => 'TextArea' );
has_field 'hidden' => ( type => 'Hidden' );
@@ -65,7 +74,8 @@ use HTML::FormHandler::Field::Text;
]
);
- has_field 'submit' => ( type => 'Submit', value => 'Update' );
+ has_field 'submit' => ( type => 'Submit', value => '>>> Update' );
+ has_field 'reset' => ( type => 'Reset', value => '<<< Reset' );
has '+dependency' => (
default => sub {
@@ -77,18 +87,18 @@ use HTML::FormHandler::Field::Text;
sub options_fruit {
return (
- 1 => 'apples',
- 2 => 'oranges',
- 3 => 'kiwi',
+ '"apples"' => '"apples"',
+ '<oranges>' => '<oranges>',
+ '&kiwi&' => '&kiwi&',
);
}
sub options_vegetables {
return (
- 1 => 'lettuce',
- 2 => 'broccoli',
- 3 => 'carrots',
- 4 => 'peas',
+ '<lettuce>' => '<lettuce>',
+ 'broccoli' => 'broccoli',
+ 'carrots' => 'carrots',
+ '& peas' => '& peas',
);
}
}
@@ -99,25 +109,33 @@ ok( $form, 'create form' );
my $output10 = $form->field('opt_in')->render;
is(
$output10, '
-<div><label class="label" for="opt_in">Opt in: </label> <br /><input type="radio" value="0" name="opt_in" id="opt_in.0" checked="checked" />No<br /><input type="radio" value="1" name="opt_in" id="opt_in.1" />Yes<br /></div>
+<div><label class="label" for="opt_in">Opt in: </label> <br /><input type="radio" value="no & never" name="opt_in" id="opt_in.0" checked="checked" />No & Never<br /><input type="radio" value=""yes"" name="opt_in" id="opt_in.1" />Yes<br /></div>
', 'output from radio group'
);
+my $output12 = $form->field('comedians')->render;
+is(
+ $output12, '
+<div><label class="label" for="comedians">Comedians: </label> <br /><input type="checkbox" value="keaton" name="comedians" id="comedians.0" />Buster Keaton<br /><input type="checkbox" value="chaplin" name="comedians" id="comedians.1" />Charly Chaplin<br /><input type="checkbox" value="laurel & hardy" name="comedians" id="comedians.2" />Stan Laurel & Oliver Hardy<br /></div>
+', 'output from checkbox group'
+);
+
my $params = {
test_field => 'something',
number => 0,
- fruit => 2,
- vegetables => [ 2, 4 ],
+ fruit => '<oranges>',
+ vegetables => [ 'broccoli', '& peas' ],
active => 'now',
- comments => 'Four score and seven years ago...',
+ comments => 'Four score and seven years ago...</textarea>',
hidden => '1234',
selected => '1',
'start_date.month' => '7',
'start_date.day' => '14',
'start_date.year' => '2006',
two_errors => 'aaa',
- opt_in => 0,
+ opt_in => 'no & never',
plain => 'No divs!!',
+ comedians => [ 'chaplin', 'laurel & hardy' ],
};
$form->process($params);
@@ -143,7 +161,7 @@ my $output2 = $form->field('fruit')->render;
is(
$output2,
'
-<div><label class="label" for="fruit">Fruit: </label><select name="fruit" id="fruit"><option value="1" id="fruit.0" >apples</option><option value="2" id="fruit.1" selected="selected">oranges</option><option value="3" id="fruit.2" >kiwi</option></select></div>
+<div><label class="label" for="fruit">Fruit: </label><select name="fruit" id="fruit"><option value=""apples"" id="fruit.0">"apples"</option><option value="<oranges>" id="fruit.1" selected="selected"><oranges></option><option value="&kiwi&" id="fruit.2">&kiwi&</option></select></div>
',
'output from select field'
);
@@ -152,7 +170,7 @@ my $output3 = $form->field('vegetables')->render;
is(
$output3,
'
-<div><label class="label" for="vegetables">Vegetables: </label><select name="vegetables" id="vegetables" multiple="multiple" size="5"><option value="1" id="vegetables.0" >lettuce</option><option value="2" id="vegetables.1" selected="selected">broccoli</option><option value="3" id="vegetables.2" >carrots</option><option value="4" id="vegetables.3" selected="selected">peas</option></select></div>
+<div><label class="label" for="vegetables">Vegetables: </label><select name="vegetables" id="vegetables" multiple="multiple" size="5"><option value="<lettuce>" id="vegetables.0"><lettuce></option><option value="broccoli" id="vegetables.1" selected="selected">broccoli</option><option value="carrots" id="vegetables.2">carrots</option><option value="& peas" id="vegetables.3" selected="selected">& peas</option></select></div>
',
'output from select multiple field'
);
@@ -170,7 +188,7 @@ my $output5 = $form->field('comments')->render;
is(
$output5,
'
-<div><label class="label" for="comments">Comments: </label><textarea name="comments" id="comments" rows="5" cols="10">Four score and seven years ago...</textarea></div>
+<div><label class="label" for="comments">Comments: </label><textarea name="comments" id="comments" rows="5" cols="10">Four score and seven years ago...</textarea></textarea></div>
',
'output from textarea'
);
@@ -211,14 +229,21 @@ is(
my $output9 = $form->field('submit')->render;
is(
$output9, '
-<div><input type="submit" name="submit" id="submit" value="Update" /></div>
+<div><input type="submit" name="submit" id="submit" value=">>> Update" /></div>
', 'output from Submit'
);
+my $output9a = $form->field('reset')->render;
+is(
+ $output9a, '
+<div><input type="reset" name="reset" id="reset" value="<<< Reset" /></div>
+', 'output from Reset'
+);
+
$output10 = $form->field('opt_in')->render;
is(
$output10, '
-<div><label class="label" for="opt_in">Opt in: </label> <br /><input type="radio" value="0" name="opt_in" id="opt_in.0" checked="checked" />No<br /><input type="radio" value="1" name="opt_in" id="opt_in.1" />Yes<br /></div>
+<div><label class="label" for="opt_in">Opt in: </label> <br /><input type="radio" value="no & never" name="opt_in" id="opt_in.0" checked="checked" />No & Never<br /><input type="radio" value=""yes"" name="opt_in" id="opt_in.1" />Yes<br /></div>
', 'output from radio group'
);
@@ -228,6 +253,15 @@ is(
<fieldset class="main_fieldset">', 'Form start OK'
);
+$output12 = $form->field('comedians')->render;
+is(
+ $output12,
+ '
+<div><label class="label" for="comedians">Comedians: </label> <br /><input type="checkbox" value="keaton" name="comedians" id="comedians.0" />Buster Keaton<br /><input type="checkbox" value="chaplin" name="comedians" id="comedians.1" checked="checked" />Charly Chaplin<br /><input type="checkbox" value="laurel & hardy" name="comedians" id="comedians.2" checked="checked" />Stan Laurel & Oliver Hardy<br /></div>
+',
+ 'output from checkbox group'
+);
+
my $output = $form->render;
ok( $output, 'get rendered output from form' );
@@ -264,7 +298,7 @@ is( $form->field('omega')->render, '<h1>You got here!</h1>', 'omega rendered
has_field 'no_widget' => ( widget => 'no_widget' );
}
dies_ok( sub { Test::NoWidget->new }, 'dies on no widget' );
-throws_ok( sub { Test::NoWidget->new }, qr/not able to load/, 'no widget throws message' );
+throws_ok( sub { Test::NoWidget->new }, qr/Can't find /, 'no widget throws message' );
$form = Test::Form->new( widget_form => 'Table', widget_wrapper => 'Table' );
ok( $form->can('render'), 'form has table widget' );
@@ -290,6 +324,8 @@ ok( $outputT, 'output from table rendering' );
);
has_field 'bar' => ( widget_tags =>
{wrapper_start => '<span>', wrapper_end => '</span>'});
+ has_field 'baz' => ( widget_tags =>
+ {wrapper_start => '', wrapper_end => ''});
}
$form = Test::Tags->new;
@@ -302,4 +338,8 @@ is( $form->field('bar')->render, '
<span><label class="label" for="bar">Bar: </label><input type="text" name="bar" id="bar" value="" /></span>
', 'field renders with custom widget_tags' );
+is( $form->field('baz')->render, '
+<label class="label" for="baz">Baz: </label><input type="text" name="baz" id="baz" value="" />
+', 'field renders with empty widget_tags' );
+
done_testing;
diff --git a/t/xt/custom_fields.t b/t/xt/custom_fields.t
index c4e33a8..47ccff8 100644
--- a/t/xt/custom_fields.t
+++ b/t/xt/custom_fields.t
@@ -54,4 +54,30 @@ ok( $form, 'form builds' );
ok( $form->field('my_date'), 'the field is there' );
is( $form->field('my_date')->render, '<p>Create your rendering here...</p>', 'renders ok' );
+{
+ package Test2::Widget::Field::SimpleWidget;
+ use Moose::Role;
+ sub render { "I'am simple widget" }
+}
+{
+ package Test2::Field::CustomWidgetCompoundField;
+ use HTML::FormHandler::Moose;
+ extends 'HTML::FormHandler::Field::Compound';
+ has_field 'my_text' => ( type => 'Text', widget => 'SimpleWidget' );
+}
+{
+ package Test2::Form::Compound;
+ use HTML::FormHandler::Moose;
+ extends 'HTML::FormHandler';
+ has '+field_name_space' => ( default => sub { 'Test2::Field' } );
+ has '+widget_name_space' => ( default => sub { ['Test2::Widget'] } );
+ has_field 'test' => ( type => '+CustomWidgetCompoundField' );
+}
+{
+ my $form = Test2::Form::Compound->new;
+ ok( $form, 'form builds' );
+ ok( $form->field('test.my_text'), 'the field is there' );
+ is( $form->field('test.my_text')->render, "I'am simple widget", 'renders ok');
+}
+
done_testing;
diff --git a/t/xt/init.t b/t/xt/init.t
index 98b5d72..d153ce6 100644
--- a/t/xt/init.t
+++ b/t/xt/init.t
@@ -1,6 +1,15 @@
use strict;
use warnings;
-use Test::More tests => 7;
+use Test::More;
+
+{
+ package My::Default;
+ use Moose::Role;
+
+ sub build_default_over_obj {
+ return 'From Method';
+ }
+}
{
package My::Other::Form;
@@ -9,30 +18,30 @@ use Test::More tests => 7;
has '+name' => ( default => 'testform_' );
has_field 'optname' => ( temp => 'First' );
- has_field 'reqname' => ( required => 1 );
+ has_field 'reqname' => ( required => 1, default_over_obj => 'From Attribute' );
+ has_field 'altname' => ( traits => ['My::Default'] );
has_field 'somename';
- sub default_reqname {
- my $self = shift;
- return 'From Method';
- }
sub default_somename {
my $self = shift;
return 'SN from meth';
}
}
-my $init_object = { reqname => 'Starting Perl', optname => 'Over Again' };
+my $init_object = { reqname => 'Starting Perl', optname => 'Over Again', altname => 'test' };
my $form = My::Other::Form->new;
ok( $form, 'get form' );
my $params = { reqname => 'Sweet', optname => 'Charity', somename => 'Exists' };
$form->process( init_object => $init_object, params => $params );
ok( $form->validated, 'form with init_obj & params validated' );
-is( $form->field('reqname')->init_value, 'From Method', 'correct init_value');
+is( $form->field('reqname')->init_value, 'From Attribute', 'correct init_value');
is( $form->field('optname')->init_value, 'Over Again', 'correct init_value no meth');
+is( $form->field('altname')->init_value, 'From Method', 'correct init_value from trait');
is( $form->field('somename')->init_value, 'SN from meth', 'correct for init_obj undef');
is( $form->field('somename')->value, 'Exists', 'correct value for init_obj undef');
$form = My::Other::Form->new( init_object => $init_object );
is( $form->field('somename')->init_value, 'SN from meth', 'correct init_value new w init_obj');
+
+done_testing;
diff --git a/t/xt/load_field.t b/t/xt/load_field.t
index 473334c..af826d8 100644
--- a/t/xt/load_field.t
+++ b/t/xt/load_field.t
@@ -15,6 +15,7 @@ use lib 't/lib';
has_field 'field_one' => ( type => '+AltText', another_attribute => 'one' );
has_field 'field_two' => ( type => '+AltText', another_attribute => 'two' );
has_field 'field_three' => ( type => '+AltText', another_attribute => 'three' );
+ has_field 'field_four' => ( type => 'AltText', another_attribute => 'four' );
}
@@ -25,6 +26,7 @@ my $params = {
field_one => 'one two three four',
field_two => 'one three four',
field_three => 'one three four',
+ field_four => 'four',
};
$form->process( $params );
@@ -38,6 +40,7 @@ is( $form->field('field_two')->errors->[0],
'Fails AltText validation', 'get error message' );
ok( !$form->field('field_three')->has_errors, 'field three has no error');
+ok( !$form->field('field_four')->has_errors, 'field four has no error');
{
package Field::Text;
diff --git a/t/xt/locale.t b/t/xt/locale.t
index fbe1fd4..797bb3e 100644
--- a/t/xt/locale.t
+++ b/t/xt/locale.t
@@ -93,7 +93,7 @@ $form->field('test_field')->add_error('You won');
is_deeply($form->field('test_field')->errors, ['You won'], 'error is translated into xx_xx');
# translating a known label
-is($form->field('test_field')->label, 'Grfg svryq', 'label rot13 to xx_xx');
+is($form->field('test_field')->loc_label, 'Grfg svryq', 'label rot13 to xx_xx');
# remove from environment variable, so we can use builder
delete $ENV{LANGUAGE_HANDLE};
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libhtml-formhandler-perl.git
More information about the Pkg-perl-cvs-commits
mailing list