md-autocomplete results disappearing on blur - problematic on iOS Safari
The autocomplete on safari iOS(8) is not working properly. If you try to hide the iOS-keyboard (e.g. tap on the button in the lower right corner of the keyboard), to see more then the top three results, a blur event seems to be fired and the results disappear.
You can see/test the described behavior on the demos page (v. 0.10.0).
Fot those who encounter the same problem, a quick & dirty fix can be done by adding the following to the blur function to close the autocomplete on the second blur:
function blur() {
...
// IOS FIX BEGIN
var isIOS = navigator.userAgent.match(/iOS|iPad|iPhone|iPod/g) || navigator.platform.match(/iOS|iPad|iPhone|iPod/g) ? true : false;
if (!noBlur && isIOS) {
window.scroll(0, 0); // fix for positioning after keyboard close
ctrl.hidden = false;
var onSecondClick = function () { ctrl.hidden = true; };
document.addEventListener("click", onSecondClick);
}
// IOS FIX END
}
and another fix for the wrong positioning when closing the keyboard (handleSearchText function):
function handleSearchText(searchText, previousSearchText) {
...
// IOS FIX BEGIN
var isIOS = navigator.userAgent.match(/iOS|iPad|iPhone|iPod/g) || navigator.platform.match(/iOS|iPad|iPhone|iPod/g) ? true : false;
if (isIOS) window.scroll(0, window.innerHeight / 2); // fix for positioning after keyboard open
// IOS FIX END
}
there may be better alternatives to fix this but it works for me and the autocomplete is finally usable on iOS. Yay!
Note: The autocomplete works fine on Android Chrome, as hiding the keyboard (e.g. via hardware-back) doesn't seem to produce any events that trigger the results to disappear. But an option to keep the results open on blur would be nice anyway.
Cheers