Check for blur by clicking on div

I have input and blur. I want to keep the value. The problem is that I have autocomplete, and when users click on a sentence from the autocomplete list, the blur starts.

For example: users enter β€œiP” into the input, and then click β€œiPhone” from the autocomplete list. This cast contains the iP and iPhone values ​​(the iP storage caused by blur and the iPhone storage caused by autocomplete).

I was thinking about checking for blur triggering by clicking on the autocomplete list.

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

So, how can I check how the blur was caused?

EDIT Here's a jsFiddle that shows something similar to my problem http://jsfiddle.net/mkp8m/1

+4
source share
1 answer

Well, having autocomplete what autocomplete means, here is the solution.

Use the change autocomplete plugin event:

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

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

+1
source

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


All Articles