user1828605 user1828605 - 6 months ago 423
AngularJS Question

Is it possible to simulate `md-selected-item` on ng-blur in angular-material md-autocomplete?

I'm creating this angular app using angular-material where md-autocomplete is very helpful. The form allows users to select or enter data in a field, and the next field populates the data based on the value from the first md-autocomplete field. If the user selects the item from the list, then

md-selected-item=ctrl.selectedText
has the object that I need for the next field. However, if the user only copies a value and pastes in the md-autocomplete field and tabs to the next field, the value is not populated because
ctrl.selectedText
is
null
. Is there a way where I can simulate
md-selected-item
on
ng-blur
?

Answer

As mentioned in the comments section, you'll have to manually listen for the TAB key. https://github.com/angular/material/issues/4697 - Clearly states this feature won't be added to the library.

On the other hand, for the copy-paste issue you could add md-select-on-match directive to your autocomplete. This should automatically select the option on exact match. You might consider using md-match-case-insensitive with this option though.

Comments