Using jQuery validate and a Submit Once Functionaility together
I have this little script that alllows you to submit a form once and only once which looks like:
- $("input[type='submit']").attr("disabled", false);
- $(".empForm").submit(function(){
- $("input[type='submit']").attr("disabled", true).val("Please wait...");
- return true;
- }); //closes submit
It works great. One little problem, I'm using the .validate plugin, and when that validates fields, the submit button is turned off. I need a way to check if the form is valid. So I produced:
- // Validates the form data
- // Running before submit, otherwise HTTP process starts and we POST
- $(".empForm").validate();
- // Setting the submit button to enabled
- $("input[type='submit']").attr("disabled", false);
- // disabling the submit button after it's been pressed atleast once
- // Prevents duplicate entries in the database
- $(".empForm").submit(function(){
- // if it's valid, lock the submit button
- // if the form is not valid, they can complete and try again
- if($(".empForm").valid()){
- $("input[type='submit']").attr("disabled", true).val("Please wait...");
- return true;
- }// closes if
- }); //closes submit
When I run this little block of code on submit, the validate works, but it locks my form button not allowing me to resubmit.
Any help would be appected!