title: angularjs - Avoid losing focus in input when selecting from autocomplete
body: <p>I have an input field with jquery autocomplete and another directive on it.</p>
  
  <p>When the input field is losing focus a function is being called to perform some update using the value.</p>
  
  <p>My problem is that when selecting a value from the autocomplete list using the mouse the input field is losing focus causing the value to save.</p>
  
  <p>To avoid that behavior i changed the autocomplete directive to set the focus back to the input field after selection. The blur directive is checking for blur only after rendering </p>
  
  <pre><code>elm.bind('blur', function() { 
    // Wait for DOM to finish rendering
    $timeout(function() {
      if ( !$(elm).is(":focus")){
        scope.update();
        scope.check_dirty();
      }
    },0);
  });
  </code></pre>
  
  <p>But it dosen't seem to work.
  When reaching this function the <code>activeElement</code> is the body. </p>
  
  <p><a href="http://plnkr.co/edit/RCZL8FYjAzZkGKp2X37H?p=preview" rel="nofollow">PLUNKER example</a></p>
  
  <p>Appreciate any help with this. </p>