Skip to content

Commit

Permalink
removed validation_error_class configuration setting again
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 25, 2013
1 parent a7fc72c commit f1ff9bf
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 21 deletions.
1 change: 0 additions & 1 deletion Changes
@@ -1,6 +1,5 @@

4.51 2013-10-25
- Added validation_error_class configuration setting.

4.50 2013-10-22
- Deprecated Mojo::UserAgent::app in favor of
Expand Down
5 changes: 0 additions & 5 deletions lib/Mojolicious/Guides/Rendering.pod
Expand Up @@ -685,11 +685,6 @@ to make styling with CSS easier.
</label>
<input class="field-with-error" type="text" name="user" value="sri" />

The class can also be changed with the C<validation_error_class> configuration
setting and L<Mojo/"config">.

app->config(validation_error_class => 'my-field-with-error');

For a full list of available checks see also
L<Mojolicious::Validator/"CHECKS">.

Expand Down
6 changes: 1 addition & 5 deletions lib/Mojolicious/Plugin/TagHelpers.pm
Expand Up @@ -225,12 +225,8 @@ sub _text_area {
sub _validation {
my ($self, $name, $tag) = (shift, shift, shift);
my ($content, %attrs) = (@_ % 2 ? pop : undef, @_);

my $class = $self->app->config->{validation_error_class}
// 'field-with-error';
$attrs{class} .= $attrs{class} ? " $class" : $class
$attrs{class} .= $attrs{class} ? ' field-with-error' : 'field-with-error'
if $self->validation->has_error($name);

return _tag($tag, %attrs, defined $content ? $content : ());
}

Expand Down
18 changes: 8 additions & 10 deletions t/mojolicious/validation_lite_app.t
Expand Up @@ -142,17 +142,15 @@ $t->get_ok('/' => form => {foo => '☃☃'})->status_is(200)
->text_is('label[for="baz"]' => 'Baz')->element_exists('select')
->element_exists('input[type="password"]');

# Validation failed for required fields (custom error class)
$t->app->config(validation_error_class => 'my-field-with-error');
# Validation failed for required fields
$t->post_ok('/' => form => {foo => 'no'})->status_is(200)
->text_is('div:root' => 'in 1')
->text_is('label.custom.my-field-with-error[for="foo"]' => '<Foo>')
->element_exists('input.custom.my-field-with-error[type="text"][value="no"]')
->element_exists_not('textarea.my-field-with-error')
->element_exists_not('label.custom.my-field-with-error[for="baz"]')
->element_exists_not('select.my-field-with-error')
->element_exists_not('input.my-field-with-error[type="password"]');
delete $t->app->config->{validation_error_class};
->text_is('div:root' => 'in 1')
->text_is('label.custom.field-with-error[for="foo"]' => '<Foo>')
->element_exists('input.custom.field-with-error[type="text"][value="no"]')
->element_exists_not('textarea.field-with-error')
->element_exists_not('label.custom.field-with-error[for="baz"]')
->element_exists_not('select.field-with-error')
->element_exists_not('input.field-with-error[type="password"]');

# Failed validation for all fields
$t->get_ok('/?foo=too_long&bar=too_long_too&baz=way_too_long&yada=whatever')
Expand Down

0 comments on commit f1ff9bf

Please sign in to comment.