Open sashazykov opened 9 years ago
Error only appears if maxlength is less than length of selected element title.
Why do you want the maxlength to be less than the size of possible input string length?
It just happened and I didn't understand what was the reason of the exception. At least it should fail with the correct error message.
To me this is happening regardless of max value. If I type a character and then delete it, it gets to that place inputChangeHandler and tries to get str.length but str is null.
It might be something in my config or callbacks that is messing it up, but the default templates send searchStr to that function, and scope.searchStr is set to null in various places in the code.
There were several pull requests and commits that seem to try to handle this for specific cases, but it seems that all it needs is some fool-proofing, perhaps like this (I can submit pull request if you agree and I am not missing something here)
scope.inputChangeHandler = function(str) {
var strlen = str ? str.length : 0;
if (strlen < minlength) {
cancelHttpRequest();
clearResults();
}
else if (strlen === 0 && minlength === 0) {
scope.searching = false;
showAll();
}
// etc.
Do you see errors in this example too? http://ghiden.github.io/angucomplete-alt/#example10
No, I do not get the error in any of the examples. It seems to be caused by some of the listeners I have that affect the search string. If I change the template from ng-change="inputChangeHandler(searchStr)"
to ng-change="inputChangeHandler(searchStr || '')"
it works fine.
Still, seeing that other places in the directive already do stuff like ...!scope.searchStr || scope.searchStr.length...
it seems that it should not be assuming that searchStr will never be a null.
This could happen if your 'title' field (not the 'search' field) is longer than the limit. It was my case.
I'm also experiencing this issue.
Getting this error when I press backspace after selecting some object.
angucomplete-alt 2.0.2