primeng icon indicating copy to clipboard operation
primeng copied to clipboard

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

Open praveens4all opened this issue 10 years ago • 8 comments

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"

praveens4all avatar Nov 04 '16 07:11 praveens4all

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

cagataycivici avatar Feb 16 '17 08:02 cagataycivici

@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>

kavoos avatar Sep 06 '17 11:09 kavoos

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?

SinghManvir avatar Jan 10 '19 11:01 SinghManvir

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

SinghManvir avatar Jan 10 '19 11:01 SinghManvir

I have the same issue. Any update now?

minhdtb avatar Dec 02 '19 07:12 minhdtb

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

MarcosQ avatar Mar 17 '20 21:03 MarcosQ

We need it too.

blosser avatar Jun 18 '21 14:06 blosser

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(); }

sourdoth avatar Jun 23 '21 20:06 sourdoth