Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Disable validations on form inputs with "disableClientSideValidations" #437

Merged
merged 1 commit into from

2 participants

@fgrehm

No description provided.

@bcardarella
Owner

This should be handled in ClientSideValidations.disable instead. I want to keep the jQuery functions as delegators only

@fgrehm

Cool, will ammend the change and push in a few ;-)

@fgrehm

There you go: even rebased and squashed ;-)

@fgrehm

We could remove this line as well right?

@bcardarella
Owner

@fgrehm $target.off('ClientSideValidations') is required to unbind all events

@bcardarella
Owner

@fgrehm yes removing that line is OK as it is now redundant

@fgrehm

I think this is it right?

@bcardarella bcardarella merged commit 1d18d47 into from
@bcardarella
Owner

Thank you!

@fgrehm

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
12 coffeescript/rails.validations.coffee
@@ -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) ->
View
13 test/javascript/public/test/form_builders/validateForm.js
@@ -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"]');
View
15 vendor/assets/javascripts/rails.validations.js
@@ -135,7 +135,6 @@
var $form, key;
$form = $(form);
ClientSideValidations.disable(form);
- ClientSideValidations.disable($form.find(':input'));
for (key in form.ClientSideValidations.settings.validators) {
form.ClientSideValidations.removeError($form.find("[name='" + key + "']"));
}
@@ -146,11 +145,15 @@
var $target;
$target = $(target);
$target.off('.ClientSideValidations');
- $target.removeData('valid');
- $target.removeData('changed');
- return $target.filter(':input').each(function() {
- return $(this).removeAttr('data-validate');
- });
+ if ($target.is('form')) {
+ return ClientSideValidations.disable($target.find(':input'));
+ } else {
+ $target.removeData('valid');
+ $target.removeData('changed');
+ return $target.filter(':input').each(function() {
+ return $(this).removeAttr('data-validate');
+ });
+ }
};
window.ClientSideValidations.enablers = {
Something went wrong with that request. Please try again.