views:

44

answers:

2

I'm writing up custom code for a CMS for a website. When a user clicks on the submit button (created with jQuery UI), it calls the click event on the button, which in turn calls a submit event, which submits the form.

Said form also checks specific fields to see if they have text, and will show error messages and deactivate the submit button until the issues are resolved. To do this, I currently use .focus(), which has a .blur() function inside it which checks to see if the error was fixed and removes the notice if so (and if there's no other errors, re-activates the button).

Now, the issue I have is that if the user edits one of the fields being checked at any time, if they don't click out of it and try submitting the form data, the .blur() function takes control (as it should by how this is coded), so it takes a second click to submit the form data.

Is there a way to have .submit() take precedence over .blur() in jQuery so this issue can't occur (for now I can simply tell the users using this to not do the steps to cause it)?

(If you guys need code I can try posting some bits of it in here.)

A: 

Try stopping the event propagation of the onblur event:

$(form).submit(function(){
  blur.stopPropagation()
...
});

See here: http://api.jquery.com/event.stopPropagation/

nicholasklick
A: 

After thinking about it a bit last night I realized that if I did a quick check to make sure if the error was visible or not before I called blur(), it would fix my problem (did a quick test and it seems to have).

Thanks for the suggestion about the event propagation stop, though, I'll have to keep that in mind.

Shawn Collier