I am using Position Absolute's jQuery validationEngine but I need to remove it after attaching it to a form.
I have 2 submit buttons on my form - one for save and one for save as draft.
I attach the validationEngine to the form when Save is clicked. If the validation fails, and the user clicks Save as Draft (by passing the validation), the validation engine is still attached to the form from when they clicked "save".
What I want to do is:
- allow the user to attempt to save
- validation fails and error is displayed
- and allow them to click save as draft without any validation being performed
I tried the unbind function and it appears to work, but it breaks the submit on the button completely. I just want to remove the validationEngine and allow everything else to work as it was.
Thanks
Create global Validator variable
var globalValidator = null
Perform your validator logoc----
Then reset as per your logic using
That library doesn't seem to have any support for unbinding at runtime (which is pretty poor design if you ask me).
Here is the code that binds the 'submit'.
The problem is, if you have more than one submit event handler attached to that form,
.unbind('submit')
will kill all of the events you had bound.Assuming that the event was the last to be bound, you might be able to strip only the last event handler attached to submit:
I added a function to the bottom of the validationEngine javascript file:
You pass in the jQuery form element. You could, of course, do this outside the validationEngine javascript file, I just found it easier to lump everything together :-)
The important bit is that you use both unbind AND die.