Clearing input model for typeahead on blur does not work if results list is present
Bug description:
- Trying to clear the input model programmatically on blur event does not work if the result window is present and results are showing
Link to minimally-working plunker that reproduces the issue:
http://plnkr.co/edit/XSJLmqnPei2ZObg3KVIT?p=preview
- In search type
lkjhsdfsdfand blur, notice the text clears correctly - In search type 'ma' and notice results are present. Blur the input and notice the text stays in the input
The same issue happens if you try to set the value of the input directly as well.
Version of Angular, ng-bootstrap, and Bootstrap:
Angular: 4.0.1
ng-bootstrap: 1.0.0-alpha.22
Bootstrap: 4.0.0-alpha.6
What is happening is after the user clears the model on blur event of the input, the dismissPopup function is setting it to the old user value. This code is in place due to the showHint option.
I already have a patch which would fix #1276, but this bug would still exist if the user chose not to use the editable=false option and tried to control it themselves.
@pkozlowski-opensource, what are your thoughts on this? Should I put up the review anyways and we can discuss if this bug would matter after that, or should we aim to fix it so the user could control it themselves too?
I ended up putting up the review for discussion purposes.
This line in the review makes it work when etiable=false, by clearing the private _userInput.
Not sure if we need to fix how dismissPopup works, or if we should just go with the review I have out and close this bug as won't fix.
what is the status? is it fixed?
There is a pull request but it is pending, and has now some branch conflicts.
One issue I see to the fix that deeg put for review is that it sets the input to null instead of the [(ngModel)] if one was previously selected.
onFocus = () => {
//clear the model
this.model = new Model();
}
onBlur = () => {
//set to current selected model
this.model = this.previousModel;
}
onSelectItem = (item: Model) => {
this.model = item;
this.previousModel = this.model;
this.selectItem.emit(this.model);
}
Perhaps modifying the dismissPopup function would be a better option:
dismissPopup() {
if (this.isPopupOpen()) {
this._closePopup();
this._writeInputValue(this._userInput); //not sure the purpose of writing the input value
}
}
Here is a plunker I forked from yours: http://plnkr.co/edit/XIVlMJ8V0iUcC0npUfwG?p=preview
One issue I see to the fix that deeg put for review is that it sets the input to null instead of the [(ngModel)] if one was previously selected.
that's the preferred behavior for my case, so perhaps it should be configurable
I agree with @mattyb. There was a value, then the user change it with another that is not valid, so if he leaves the field, the value is not valid and i see no reason to keep previous value instead of erasing the invalid value.
One issue I see to the fix that deeg put for review is that it sets the input to null instead of the [(ngModel)] if one was previously selected.
that's the preferred behavior for my case, so perhaps it should be configurable
This looks useful to me to understand why my dropdown list isn't closing when less that two characters are typed. However how would I adapt this to work with formControlName, i.e reactive forms instead of ngModel:
`this.addForm = fb.group({
typeaheadFormControlName: fb.control(''),` ....
Has there been any further discussion on this topic? In my testing, the input box still isn't cleared when editable = false. I'm struggling to find a workaround that will clear the box, but the change, blur, and ngModelChange events all fire before the popup is closed.
@pflugs30 I assume given the time you've already found away around this, but if not, I solved the same problem as you by writing a custom directive