Any way to override .blur () if .submit () is called in jQuery?

I am writing my own CMS code for a website. When a user clicks a submit button (created using jQuery UI), it triggers a button click event, which in turn triggers a submit event, which submits the form.

The specified form also checks certain fields to see if they have text, and will display error messages and deactivate the submit button until the problems are fixed. To do this, I am currently using .focus (), which has a .blur () function that checks if the error has been fixed, and whether this notification is deleted (if there are no other errors, it activates the button).

Now the problem is that if the user edits one of the fields that will be checked at any time, if they do not exit it and do not try to send form data, the .blur () function takes control (as it should be, how it is encoded ), so a second click is required to submit the form data.

Is there a way to have .submit () take precedence over .blur () in jQuery so this problem cannot happen (now I can just tell users using this not to take steps to call this)?

(If you need some code, I can try posting a few bits here).

+3
source share
3 answers

, , , , , blur(), ( , ).

, , .

0

onblur:

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

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

+2

onFocusout . .

, , .

//           var setTimer = {               : null           }

        $('input,select').blur(function () {
            setTimer.timer = setTimeout(function () {
               functionCall();
            }, 1000);
        });

        $('input,select').focus(function () {
            setTimer.timer = setTimeout(function () {
                functionCall();
            }, 1000);
        });

        $("#btn").click(function () {
            clearTimeout(setTimer.timer);
            functionCall();
        });   
+2
source

Source: https://habr.com/ru/post/1756851/


All Articles