ngAutocomplete icon indicating copy to clipboard operation
ngAutocomplete copied to clipboard

Solution for autocomplete model not updating when pressing enter

Open justinbc820 opened this issue 11 years ago • 3 comments

I would type some characters into the autocomplete text field such as 'ap', then I would use my arrow keys to navigate to one of the autocompleted options. Then, I would hit enter which would submit the form. However, when I press enter, the ng-model still only had a value of 'ap' instead of 'appliance store' (or whatever starts with 'ap').

So, in order to solve that, I added the following code at line 83 of your directive. I think that a lot of people would be looking for a fix like this.

// Custom code to make autocomplete field pass autocomplete value to the model when enter is pressed element.bind("keydown keypress", function(event) { if(event.which === 13) { scope.$apply(function () { controller.$setViewValue(element.val()); }); } }); // end of custom code

justinbc820 avatar Oct 02 '14 02:10 justinbc820

:+1:

PierrickP avatar Dec 12 '14 17:12 PierrickP

:+1::+1::+1::+1::+1:

iazi avatar Feb 06 '15 16:02 iazi

:+1::+1::+1::+1::+1: from here as well.

dnlmzw avatar Feb 26 '15 11:02 dnlmzw