Skip to content
Browse files

don't validate disabled fields

  • Loading branch information...
1 parent bd7b20b commit 64535afae0efaf98c0a3d789e88570b21d9dac8b @gshank committed
View
2 lib/HTML/FormHandler/Field/Date.pm
@@ -20,7 +20,7 @@ or DateTime strftime formats. (Default format is format => '%Y-%m-%d'.)
oo - "%j" - day of the year (three digit)
D - "%a" - day name short
DD - "%A" - day name long
- m - "%{day_of_month" - month of year (no leading zero)
+ m - "%{day_of_month}" - month of year (no leading zero)
mm - "%m" - month of year (two digit) "%m"
M - "%b" - month name short
MM - "%B" - month name long
View
2 lib/HTML/FormHandler/Fields.pm
@@ -153,7 +153,7 @@ sub _fields_validate {
# validate all fields
my %value_hash;
foreach my $field ( $self->all_fields ) {
- next if ( $field->is_inactive || !$field->has_result );
+ next if ( $field->is_inactive || $field->disabled || !$field->has_result );
# Validate each field and "inflate" input -> value.
$field->validate_field; # this calls the field's 'validate' routine
$value_hash{ $field->accessor } = $field->value
View
2 lib/HTML/FormHandler/Validate.pm
@@ -109,7 +109,7 @@ sub validate_field {
$field->_inner_validate_field();
$field->_apply_actions;
- $field->validate;
+ $field->validate( $field->value );
$field->test_ranges;
$field->_validate($field) # form field validation method
if ( $field->has_value && defined $field->value );
View
12 t/field_setup/disabled.t
@@ -4,7 +4,7 @@ use Test::More;
use Data::Dumper;
# tests that an init_value provided by item/init_object is used
-# for disabled fields
+# for disabled fields, and that disabled fields are not validated.
{
{
package MyApp::Test::Form1;
@@ -14,7 +14,15 @@ use Data::Dumper;
has_field 'foo' => ( type => 'Select', disabled => 1 );
has_field 'bar';
has_field 'user' => ( type => 'Compound', required => 1 );
- has_field 'user.email_address' => ( disabled => 1, required => 1 );
+ has_field 'user.email_address' => ( disabled => 1, required => 1,
+ validate_method => \&check_email
+ );
+ sub check_email {
+ my $self = shift;
+ if ( $self->value && $self->value =~ /joe/ ) {
+ $self->add_error("No emails with 'joe'");
+ }
+ }
has_field 'save' => ( type => 'Submit' );
}

0 comments on commit 64535af

Please sign in to comment.
Something went wrong with that request. Please try again.