12

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.

M Khan
  • 225
  • 1
  • 4
  • 14

1 Answers1

44

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.

Luís Cruz
  • 14,780
  • 16
  • 68
  • 100
  • No that didn't work. I am getting a "Uncaught TypeError: undefined is not a function". – M Khan Apr 28 '14 at 14:00
  • 1
    Verify the following fiddle http://jsfiddle.net/dDaU7/ and compare it to your code. If you have any trouble, post your code here or create a jsfiddle. – Luís Cruz Apr 28 '14 at 14:16
  • 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();** – M Khan Apr 28 '14 at 14:31