Jquery define own events?

Is it possible to determine an input event that fires under these circumstances.

a) is called on blur of input IF the remaining conditions are true
b) if the autocomplete list is visible halt the event until it is closed
c) if the autocomplete list closes without an item being selected then the event is fired
d) if the autocomplete list closes with an item being selected the event is not fired
e) if the reason the blur was caused was because an item in the autocomplete was clicked the event is not fired

As you can see, this event has a lot. I can’t use the usual setTimeout in the blur event, because the user can sit in the autocomplete list without selecting anything.

Perhaps I can set the variable to autocomplete so that we know that it is still open.
if the timer expires and autocomplete is still open, we can reset the timer.
then upon closing we can disable the variable.
or when selecting an item can we turn off the timer?

What do you think?

+3
source share
2 answers

Ability to trigger your own events using the Trigger function . This means that you can trigger an event at individual points in your code, so you don't need to write complex constructs.

Just call it: $('.yourClass').trigger('myEvent');

Linking to this event can be done through .bind(), i.e.$('.yourClass').bind('myEvent', function () { });

+5
source

fling plugin, . :

$(yourinput).blur(function(){
    if(....your condition....)
        $.fling('publish','YourEventName',your data in json);
}

:

 $.fling('subscribe','YourEventName', function(){
 });
0

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


All Articles