How to get the parsley.js reset() method to reset the form
Asked Answered
N

1

13

I am having hard time figuring out to get the parsley.js 2.0 reset() method to fire upon clicking the reset button. This is my reset button:

<input type="reset" id="resetForm" value="Reset" />

I have setup a click event:

$('#resetForm').click(function () {
    $('#myForm').parsley('reset');
});

Obviously this doesn't work. And I can't figure out how to call the reset() method. I understand that it is part of the ParsleyUI but how do I get it to fire ?

I have tried to access a bunch of different ways but obviously my lack of significant JS/jQuery knowledge is getting the best of me.

Any help will be appreciated.

Thank You.

Nobles answered 11/4, 2014 at 13:45 Comment(0)
J
45

Instead of using

$('#myForm').parsley('reset');

Try using

$('#myForm').parsley().reset();

Assuming your form has the id "myForm" and you have no JS errors, this should work.

Janettejaneva answered 26/4, 2014 at 20:56 Comment(3)
No that didn't work. I am getting a "Uncaught TypeError: undefined is not a function".Nobles
Verify the following fiddle jsfiddle.net/dDaU7 and compare it to your code. If you have any trouble, post your code here or create a jsfiddle.Domenic
Thanks for your solution. I realized that I was forgetting that I had done this: parsleyJs = new Parsley('form');. And hence to call the reset function I can just do this: parsleyJs.reset();Nobles

© 2022 - 2024 — McMap. All rights reserved.