question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Clearing input model for typeahead on blur does not work if results list is present

See original GitHub issue

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 lkjhsdfsdf and 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

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:8
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
mikeysteelecommented, Sep 10, 2020

@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

1reaction
khodgkinscommented, Oct 6, 2017

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular ngbTypeahead doesn't reset value of input on blur
Show activity on this post. I'm using the bootstrap ngbTypeahead of Angular2+ and I want to clean the input when lose focus and...
Read more >
AutoComplete - PrimeNG - PrimeFaces
When present, autocomplete clears the manual input if it does not match of the suggestions to force only accepting values from the suggestions....
Read more >
<input>: The Input (Form Input) element - HTML
A Boolean attribute which, if present, indicates that the user should not be able to interact with the input. Disabled inputs are typically ......
Read more >
Directives > mdAutocomplete - AngularJS Material
Parameter Type Description md‑search‑text expression expression A model to bind the search query text to. md‑selected‑item object object A model to bind the selected item...
Read more >
C# tutorial on autocomplete and suggestions - Azure
Add autocomplete and suggestions to collect search term input from users ... UI library to present the dropdown list of suggested results.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found