Skip to content

Commit

Permalink
Disable validations on form inputs with "disableClientSideValidations"
Browse files Browse the repository at this point in the history
  • Loading branch information
fgrehm committed Nov 19, 2012
1 parent 8340189 commit 231f06f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
12 changes: 7 additions & 5 deletions coffeescript/rails.validations.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ window.ClientSideValidations.selectors =
window.ClientSideValidations.reset = (form) ->
$form = $(form)
ClientSideValidations.disable(form)
ClientSideValidations.disable($form.find(':input'))
for key of form.ClientSideValidations.settings.validators
form.ClientSideValidations.removeError($form.find("[name='#{key}']"))

Expand All @@ -121,10 +120,13 @@ window.ClientSideValidations.reset = (form) ->
window.ClientSideValidations.disable = (target) ->
$target = $(target)
$target.off('.ClientSideValidations')
$target.removeData('valid')
$target.removeData('changed')
$target.filter(':input').each ->
$(@).removeAttr('data-validate')
if $target.is('form')
ClientSideValidations.disable($target.find(':input'))
else
$target.removeData('valid')
$target.removeData('changed')
$target.filter(':input').each ->
$(@).removeAttr('data-validate')

window.ClientSideValidations.enablers =
form: (form) ->
Expand Down
13 changes: 13 additions & 0 deletions test/javascript/public/test/form_builders/validateForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,19 @@ test('Resetting client side validations', 9, function() {
ok(input.parent().find('label:contains("must be present")')[0]);
});

test('Disable client side validations on all child inputs', 3, function() {
var form = $('form#new_user'), input = form.find('input#user_name');
var label = $('label[for="user_name"]');

form.disableClientSideValidations();

input.trigger('focusout');

ok(!input.parent().hasClass('field_with_errors'));
ok(!label.parent().hasClass('field_with_errors'));
ok(!input.parent().find('label:contains("must be present")')[0]);
});

asyncTest('Handle disable-with', 1, function() {
var form = $('form#new_user'), input = form.find('input#user_name');
var label = $('label[for="user_name"]');
Expand Down
15 changes: 9 additions & 6 deletions vendor/assets/javascripts/rails.validations.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 231f06f

Please sign in to comment.