Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

it is not possible to reset input value for typeahead component #2816

Closed
mdelprado86 opened this issue Oct 18, 2018 · 3 comments · Fixed by #2891
Closed

it is not possible to reset input value for typeahead component #2816

mdelprado86 opened this issue Oct 18, 2018 · 3 comments · Fixed by #2891

Comments

@mdelprado86
Copy link

Bug description:

For the typeahead component, it is not possible to clear the model after the results list appears. If the results list doesn't appear, the model can be cleared from a button without problem

Steps to reproduce:

You can fork a StackBlitz from one of our demos and use it as a starting point.

Versions of Angular, ng-bootstrap and Bootstrap:

Angular: 6.1.0

ng-bootstrap: 3.3.0

Bootstrap: 4.0

@angelika
Copy link

Does anybody know a possible workaround for this? I don't care how dirty it is, I just need it to work :D

@wannadream
Copy link

wannadream commented Nov 4, 2018

Try this:

clear(){
    setTimeout(()=>{
      this.model = '';
    }, 200);
  }

https://stackblitz.com/edit/angular-rybwwn-vzxdf1

@wannadream
Copy link

wannadream commented Nov 5, 2018

The problem occurs here: https://github.com/ng-bootstrap/ng-bootstrap/blob/master/src/typeahead/typeahead.ts

Line 224:

dismissPopup() {
    if (this.isPopupOpen()) {
      this._closePopup();
      this._writeInputValue(this._inputValueBackup);
    }
  }

Whenever pop-up is dimissed, the previous backed up value was written back.

Proposed change:

if (this.isPopupOpen()) {
      this._closePopup();
      if (this._elementRef.nativeElement.value !== '') {
        this._writeInputValue(this._inputValueBackup);
      }
    }

wannadream added a commit to wannadream/ng-bootstrap that referenced this issue Nov 5, 2018
benouat pushed a commit to benouat/ng-bootstrap that referenced this issue Nov 28, 2018
@benouat benouat added this to the 4.0.1 milestone Nov 29, 2018
benouat pushed a commit to benouat/ng-bootstrap that referenced this issue Dec 5, 2018
benouat pushed a commit to benouat/ng-bootstrap that referenced this issue Dec 5, 2018
benouat pushed a commit that referenced this issue Dec 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment