Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate destroy is not working for me #52

Open
binu101 opened this issue Feb 28, 2014 · 7 comments
Open

Validate destroy is not working for me #52

binu101 opened this issue Feb 28, 2014 · 7 comments
Assignees

Comments

@binu101
Copy link

binu101 commented Feb 28, 2014

Hi,
I've made a dynamic validator for the web application which I'm currently working on.

I dynamically build the element selector and call the form validation like this:

jQuery($el).validate();

However, when I want to reload the validation of a form, for example when loading different values from AJAX, i'm using a direct call to the form to destroy validation like:

jQuery('#create_user_form').validateDestroy();

This does not destroy validation, can you please help me?

@DiegoLopesLima
Copy link
Owner

Hi @binu101!

You can send me a snippet of your code and jQuery version?

@benperiton
Copy link

Same for me, issue is on line 307 it should be options.namespace.

@DiegoLopesLima
Copy link
Owner

Very thanks @benperiton! I'm working to fix this error.

In the meantime, you can do anything like this to "destroy" validation:

var

    form = $('form').removeData('validate').off('validate');

$('input,select,textarea').filter(function() {

    return form.is($(this).prop('form'));

}).off('validate');

To maintain current way:

$.fn.validateDestroy = function() {

    $(this).each(function() {

        var

            form = $(this).removeData('validate').off('validate');

        $('input,select,textarea').filter(function() {

            return form.is($(this).prop('form'));

        }).off('validate');

    });

};

@benperiton
Copy link

Sorry, I would have sent a pull request but been far too busy today!

@DiegoLopesLima
Copy link
Owner

Rest assured, your comment was very useful. Very thanks!

@patrickbense
Copy link

I am unable to get this quick fix to work and am having the same issue it appears. I have a field hidden by default that only shows up if an option from a select is selected. When it shows up, I require that field, but if I then select something else in that first drop down it is still required even after removing data-required etc.

Everytime I change the value of that first select I am attempting to destroy validation and then I revalidate after. Any ideas?

@projectx500
Copy link

I met with the same bug and fixed it in a similar way. So I just post it here for those looking to fix it themselves.

In addition to line 307, u have to rename namespace to nameSpace in all these lines

307 : nameSpace = options.nameSpace;
319 : fields.filter(type[0]).on('keyup.' + nameSpace, function(event) {
328 : fields.on('blur.' + nameSpace, function(event) {
337 : fields.on('change.' + nameSpace, function(event) {
346 : form.on('submit.' + nameSpace, function(event) {

Or just do a search and replace :-)

Note : This is the same bug with #62

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants