Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

md-search-text-change in md-autocomplete doesn't work when delete select text #2061

Closed
caok2709 opened this issue Mar 27, 2015 · 3 comments
Closed
Assignees
Milestone

Comments

@caok2709
Copy link

Hello guys!
I think I found a bug for md-search-test-change.
This directive can't detect search text is empty if user do this :

If user first type: "abc", the md-search-text-change do will be called. There is no problem.
However, if the user firstly input a word "abc" in the input box and then delete them together or just press delete on the keyboard ,the md-search-text-change won't get a chance to call.....
Which means: there is no way to determine if the search text is empty or not.

I know there is a button at the end for input box. If we press that clean button, the search text will gone. and the model bind to md-selected-item will gone....
Question is: you can't force user to press that button to clean the selectItem model ...

Anyone know , how to tell if the search text is empty when user clean them by the way I gave?

@caok2709
Copy link
Author

I checkout the source code of angular-material.js
on line: 10181 function handleSearchText may need to fix.
if the searchText is empty and length is less than the minLength, it will return the function .
The last two lines:
if ($scope.textChange && searchText !== previousSearchText)
$scope.textChange(getItemScope($scope.selectedItem)); won't even got called.

So we can't just return the function we still need to check the searchText and previousSearchText.
if previousSearchText is no undefined (which means it do have a value). .... then we need to run another logic. Otherwise, any function in md-search-text-change won't get called.

function handleSearchText (searchText, previousSearchText) {
self.index = -1;
//if ($scope.textChange && searchText !== previousSearchText)
// $scope.textChange(getItemScope($scope.selectedItem));
if (!searchText || searchText.length < Math.max(parseInt($scope.minLength, 10), 1)) {
self.loading = false;
self.matches = [];
self.hidden = shouldHide();
updateMessages();
return;
}
var term = searchText.toLowerCase();
if (promise && promise.cancel) {
promise.cancel();
promise = null;
}
if (!$scope.noCache && cache[term]) {
self.matches = cache[term];
updateMessages();
} else {
self.fetch(searchText);
}
self.hidden = shouldHide();
if ($scope.textChange && searchText !== previousSearchText)
$scope.textChange(getItemScope($scope.selectedItem));
}

@ThomasBurleson ThomasBurleson modified the milestone: 0.9.0 Mar 31, 2015
@robertmesserle robertmesserle added the in progress Mainly for in progress PRs, but may be used for issues that require multiple PRs label Apr 2, 2015
@ajoslin ajoslin removed the in progress Mainly for in progress PRs, but may be used for issues that require multiple PRs label Apr 2, 2015
@piyushchauhan2011
Copy link

Not working for me in 0.10 release 😞
md-search-text-change is not getting called!

@piyushchauhan2011
Copy link

Sorry working fine now.!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants