Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery define own events?

Is it possible to define an event on an input that is fired upon 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 the event has quite a bit to it. I cant use a normal setTimeout in the blur event because the user could be sitting on the the autocomplete list without actually selecting anything.

Maybe I could set a variable on autocomplete open so we know it is still open.
if the timer expires and the autocomplete is still open we can reset the timer.
then on close we can unset the variable.
or on select of an item we can unset the timer?

What do you think?

like image 577
Hailwood Avatar asked Mar 20 '26 20:03

Hailwood


1 Answers

It's possible to trigger your own events using the Trigger function. This means that you can call the event at separate points in your code, so you don't have to write complicated constructions.

Simply call like this: $('.yourClass').trigger('myEvent');

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

like image 169
Exelian Avatar answered Mar 22 '26 08:03

Exelian