horprogs / Just-validate

Modern, simple, lightweight (~5kb gzip) form validation library written in Typescript, with no dependencies (no JQuery!). Support a wide range of predefined rules, async, files, dates validation, custom error messages and styles, localization. Support writing custom rules and plugins.

Home Page:https://just-validate.dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

destroy function has no effect

cgahmann opened this issue · comments

Hi, if you build the form into a modal and then close the modal, then the form should reset and so should the validation. But this is not possible here. The validation remains and is added by 1 each time.
Here you can test it by entering 2 characters at "Name", close the modal, then open it again, then enter 2 characters again and so on.
Is there any other way to reset the validation?

Thanks for your help!

https://jsfiddle.net/xq39w7y8/

Hey, I see. It doesn't work because you create a new instance and then destroy this, but the old one is still there.
You should define a outer scope variable, initialise the library and assign the instance to this variable. And when you want to destroy it, you should call this method for existing instance which you created when you showed the popup.

Please check here https://jsfiddle.net/8aucfs61/2/

Thanks for your help! I couldn't see the forest for the trees.
In bootstrap you have a function called: getInstance. With it I can then address a specific instance, for example. But so it also works.