guillaumepotier / Parsley.js

Validate your forms, frontend, without writing a single line of javascript
http://parsleyjs.org
MIT License
9.05k stars 1.32k forks source link

`destroy` doesn't remove event bindings #1329

Closed richard-jones closed 4 years ago

richard-jones commented 4 years ago

What kind of issue is this? (put 'x' between the square brackets)

I'm attempting to conditionally remove parsley from a form (to prevent validation under certain circumstances), and I have found that destroy() does not remove the event listener, so even after I have done that the form will still validate.

To give you a bit more context, what I need is a form with two buttons, one which uses validation and the other which does not. Once parsley has been bound to the form, even after destroy the button which doesn't want validation will still always have validation applied to it. I have added an $(element).off("submit.Parsley") when I also call destroy(), which does the job, and I suspect this is all that's required in the destroy() method to completely clean up.

As an aside, it would be nice if it were possible to prevent parsley from binding submit at all, and leave it to me to decide when to call validate().

marcandre commented 4 years ago

Odd. destroy() calls _destroyUI that calls off('.Parsley') so it should be unbound. A simplistic example seems to work: https://codepen.io/marcandre/pen/bGVGMKV?editors=101

Please provide an actual simplistic counter example and I will reopen.