XCS
XCS

Reputation: 28147

Check if blur was triggered by click on div

I have an input and on blur I want to save the value. The problem is that I have autocomplete on and when the users clicks on a suggestion from the autocomplete list the blur is triggered.

For example: the users enters "iP" in the input and then clicks "iPhone" from the autocomplete list. In this caste both "iP" and "iPhone" values are stored ("iP" store triggered by blur and "iPhone" store triggered by autocomplete click).

I was thinking about checking if the blur action was triggered by a click on the autocomplete list.

$('input').blur(function(e){
  if(e.IsClickOnAutocomplete)
     return;
  else save_value;
});

So, how can I check in which way the blur was triggered?

EDIT Here, a jsFiddle that shows something simillar to my problem http://jsfiddle.net/mkp8m/1

Upvotes: 4

Views: 568

Answers (1)

VisioN
VisioN

Reputation: 145408

Ok, after making clear what autocomplete you mean, here is the solution.

Use change event of autocomplete plugin:

change: function(event, ui) {
    // save(this.value);
}

DEMO: http://jsfiddle.net/mkp8m/2/

Upvotes: 1

Related Questions