Primeng: [Feature Request] autocomplete "field" could be "fields" - Would like to display multiple properties in object

Created on 4 Nov 2016  路  8Comments  路  Source: primefaces/primeng

Currently autoComplete is accepting only one field in suggestion, I need to display multiple fields in suggestion.

example:
Obejct : address fields: streetname, suburb, country
current : field = "streetname"
expected : fields = "streetname, suburb, country"

Most helpful comment

@cagataycivici , I use template for my dropdown item and it works perfectly. But when I choose an item, I want to have both firsname and lastname to be shown and not just one field. Can you give me some tips?

<p-autoComplete 
      formControlName="trader"
      [suggestions]="traders" 
      field="lastname"
      [dropdown]="true" 
      readonly="true"
      (onDropdownClick)="handleTradersDropdown($event)"
      placeholder="Trader">
            <ng-template let-trader pTemplate="item">
                  <div>{{trader.firstname }} {{trader.lastname }}</div>
            </ng-template>
</p-autoComplete>

All 8 comments

I'd suggest using templating with item template and selected item template with 2.0.1 so you have full control of content.

@cagataycivici , I use template for my dropdown item and it works perfectly. But when I choose an item, I want to have both firsname and lastname to be shown and not just one field. Can you give me some tips?

<p-autoComplete 
      formControlName="trader"
      [suggestions]="traders" 
      field="lastname"
      [dropdown]="true" 
      readonly="true"
      (onDropdownClick)="handleTradersDropdown($event)"
      placeholder="Trader">
            <ng-template let-trader pTemplate="item">
                  <div>{{trader.firstname }} {{trader.lastname }}</div>
            </ng-template>
</p-autoComplete>

Is the above possible? I would also like the input box to display the same as defined in the item template.
@kavoos - Were you able to find a solution to this?

Another issue regarding this is open - https://github.com/primefaces/primeng/issues/4269

I have the same issue. Any update now?

This is a very helpful feature. 驴Any progress or is it impossible for now?

We need it too.

I "solved" the problem in the following way, I hope it will help you until they implement the definitive option

HTML
<!-- **NOT set/put "field" attribute** -->
<p-autoComplete #customId [(ngModel)]="value" (onSelect)="select($event)" [suggestions]="suggestions" (completeMethod)="filter($event)">
<ng-template let-v pTemplate="item">
{{v.name}} {{v.lastname}} {{v.etc}}
</ng-template>
</p-autoComplete>

TS
@ViewChild('customId', {static: false}) auto:any;

select(v : any) {
let allFilds:string = v.name+' '+v.lastname.....
this.auto.inputFieldValue = allFilds.trim();
}

Was this page helpful?
0 / 5 - 0 ratings

Related issues

just-paja picture just-paja  路  3Comments

Helayxa picture Helayxa  路  3Comments

jisqaqov picture jisqaqov  路  3Comments

garethlewis picture garethlewis  路  3Comments

Faigjaz picture Faigjaz  路  3Comments