mdAutoComplete: md-min-length = 0 causes opening of list if scope variable is modified while element is not focused #2756
Description
CodePen: http://codepen.io/londovir/pen/GJpdGR?editors=101
If you have an mdAutoComplete
on your page set with md-min-length="0"
, and your page in some way modifies the scope variable bound to the md-search-text
attribute, it will trigger open the list of options to select from, even if the mdAutoComplete
does not have the input focus. In addition, should you have code in your controller which sets the value of the scope variable in the context of a $timeout
call (or some other delayed execution), even if you set it to an empty string, the list will open as well, even without the focus.
In the CodePen, I have simulated this by putting a simple $timeout
call at the end of the controller definition which sets the scope variable to an empty string. You should see the list open automatically once the CodePen finishes loading, even though the focus is not on that element. In addition, if you set a value by clicking from the list, and then click the "Clear Search Text" button (which sets the scope variable to an empty string), it will again trigger the list opening.
Note: A simple workaround right now would be to change my code to set the scope variable to be undefined
, rather than an empty string. However, this leads to an error being thrown by the function isMinLengthMet()
, which is not desirable, and it would not solve the problem which occurs if other parts of my controller update that scope variable to a different value as that will open the list options again, even if not focused.
As I noted in the referenced issue by another user (#2767), perhaps a change in logic in the shouldHide
function which not only checks the minimum length of the search text, but also checks to see if the input box has the focus, would resolve this (and other) problems.