Skip to content
Browse files

support bundle message that has no validation rule

  • Loading branch information...
1 parent 18bf861 commit 347de4b16e4a44aef683b97abfcd00fabd80289c typester committed
Showing with 19 additions and 1 deletion.
  1. +5 −0 lib/Catalyst/Plugin/FormValidator/Simple/Auto.pm
  2. +14 −1 t/04_bundle_message.t
View
5 lib/Catalyst/Plugin/FormValidator/Simple/Auto.pm
@@ -154,6 +154,11 @@ sub setup {
$messages->{$action}{$param}{ $rule_name } = $rule->{message} if defined $rule->{message};
$rule = $rule->{rule};
}
+ elsif (ref $rule eq 'HASH' and defined $rule->{_rule} ) {
+ $messages->{$action}{$param} ||= {};
+ $messages->{$action}{$param}{ $rule->{_rule} } = $rule->{message} if defined $rule->{message};
+ undef $rule;
+ }
}
}
}
View
15 t/04_bundle_message.t
@@ -22,6 +22,9 @@ use warnings;
],
},
action2_submit => { param1 => [ 'NOT_BLANK', 'ASCII' ], },
+ action3 => {
+ param1 => [ { _rule => 'SELF', message => 'SELF!!', }, ],
+ },
},
},
);
@@ -59,12 +62,19 @@ use warnings;
$c->res->body('no errors');
}
}
+
+ sub action3 :Global {
+ my ($self, $c) = @_;
+
+ $c->set_invalid_form( param1 => 'SELF' );
+ $c->res->body( $c->form_messages('param1')->[0] );
+ }
}
use Catalyst::Test 'TestApp';
use Test::Base;
-plan tests => 14;
+plan tests => 15;
use HTTP::Request::Common;
@@ -92,3 +102,6 @@ is( $res->content, 'no errors', 'is no errors');
ok( $res = request('/action2'), 'request ok' );
is( $res->content, 'no $c->form executed', 'is no $c->form executed');
+
+# bundle message that not validation rule
+is( get('/action3'), 'SELF!!', 'self message ok');

0 comments on commit 347de4b

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