Permalink
Browse files

Disable validations on form inputs with "disableClientSideValidations"

  • Loading branch information...
1 parent 8340189 commit 231f06fb094334602eeeb9326f12394254051b67 @fgrehm committed Nov 16, 2012
@@ -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}']"))
@@ -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) ->
@@ -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"]');

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit 231f06f

Please sign in to comment.