ng2-completer icon indicating copy to clipboard operation
ng2-completer copied to clipboard

Open dropdown when we already on focus

Open marciomsm opened this issue 7 years ago • 8 comments

Are there some way to open the dropdown again when we already on focus and the mouse cursor is blinking?

I mean, when I am on focus and I want to open the dropdown again, I need to remove the focus and then focus on field again.

marciomsm avatar Jun 06 '17 00:06 marciomsm

yes, there is an open method for the component - see the demo

oferh avatar Jun 06 '17 09:06 oferh

@oferh I got this error Cannot read property 'open' of undefined. Do you have any ideia?

import { CompleterService, CompleterData, CompleterItem, CompleterCmp } from 'ng2-completer';

@ViewChild('openCloseExample') private openCloseExample: CompleterCmp;

public onOpened(isOpen: boolean) {
      this.isOpen = isOpen;
  }

  public onToggle() {
      if (this.isOpen) {
          this.openCloseExample.close();
      } else {
          this.openCloseExample.open();
          this.openCloseExample.focus();
      }
  }

marciomsm avatar Jun 06 '17 14:06 marciomsm

can you also add you html?

oferh avatar Jun 06 '17 14:06 oferh

Hi @oferh, here it is:

              <ng2-completer name="list" class="custom-dropdown"
                          [(ngModel)]="dataStr"
                          [inputName]="'list'"
                          [openOnFocus]="true"
                          (opened)="onOpened($event)"
                          [disableInput]="!isLoaded"
                          [datasource]="dataList"
                          [openOnFocus]="true"
                          [minSearchLength]="0"
                          [placeholder]="'Choose a item'"
                          (selected)="getStationSelected($event)">
              </ng2-completer>
              <span class="toggle-dropdown" (click)="onToggle()"></span>

marciomsm avatar Jun 06 '17 14:06 marciomsm

try this:

              <ng2-completer #openCloseExample
                          name="list"
                          class="custom-dropdown"
                          [(ngModel)]="dataStr"
                          [inputName]="'list'"
                          [openOnFocus]="true"
                          (opened)="onOpened($event)"
                          [disableInput]="!isLoaded"
                          [datasource]="dataList"
                          [openOnFocus]="true"
                          [minSearchLength]="0"
                          [placeholder]="'Choose a item'"
                          (selected)="getStationSelected($event)">
              </ng2-completer>
              <span class="toggle-dropdown" (click)="onToggle()"></span>

oferh avatar Jun 07 '17 15:06 oferh

Hi @oferh this works for me.

One question, if I have more then one dropdown in my template, I need to duplicate the my code, right?

Thanks.

marciomsm avatar Jun 07 '17 15:06 marciomsm

yes, but you can always create a function that gets the relevant component

oferh avatar Jun 07 '17 15:06 oferh

How to debug the dropdown I want to change the background color of the dropdown and color of the dropdown values?

MobackChetanKumar avatar Apr 27 '19 09:04 MobackChetanKumar