Multiple field for AutoComplete
[ ] bug report => Search github for a similar issue or PR before submitting [x] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primeng/wiki/Roadmap [ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=35
Multiple field for "autoComplete" for example:
<p-autoComplete [(ngModel)]="val" [suggestions]="results" (completeMethod)="search($event)" field="name,lastname"></p-autoComplete>
or
<p-autoComplete [(ngModel)]="val" [suggestions]="results" (completeMethod)="search($event)" field="name+' '+lastname"></p-autoComplete>
in two case show: name(space)lastname => Carlos Rojas (example)
*this is a suggestion, if exist other way (or better) to do this, its fine :D
thanks.
* **Browser:** [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]
<!-- All browsers where this could be reproduced -->
* **Language:** [all | TypeScript X.X | ES6/7 | ES5]
* **Node (for AoT issues):** `node --version` =
Any info regarding this item? It would be a very good addition!
Very need this feature, or custom template for single autocomplete
Any updates?
Up. We need this feature!!!
Any solutions or any updates?
Any udpates? We need this
any update?
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(); }
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(); }
thanks man . Nice and easy alternative.
You can already put any string you want for the selected item of a single autocomplete using a pipe-like function as an input for [field]
Exemple :
<p-autocomplete [field]="myCustomDisplay"/>
function myCustomDisplay(item : ItemType): string {
return `${item.firstAttribute} - ${item.secondAttribute}`;
}
Sources : https://github.com/primefaces/primeng/blob/master/src/app/components/autocomplete/autocomplete.ts#L591
this.field ? ObjectUtils.resolveFieldData(value, this.field) : value;
https://github.com/primefaces/primeng/blob/master/src/app/components/utils/objectutils.ts#L60
public static resolveFieldData(data: any, field: any): any {
if (data && field) {
if (this.isFunction(field)) {
return field(data);
}
else if (field.indexOf('.') == -1) {
return data[field];
}
else {
let fields: string[] = field.split('.');
let value = data;
for(let i = 0, len = fields.length; i < len; ++i) {
if (value == null) {
return null;
}
value = value[fields[i]];
}
return value;
}
}
else {
return null;
}
}
N.B
- field type is string and should be any (or the type of field param for resolveFieldData if it becomes more precise one day)
- documentation should be updated
Hi,
So sorry for the delayed response! Improvements have been made to many components recently, both in terms of performance and enhancement. Therefore, this improvement may have been developed in another issue ticket without realizing it. You can check this in the documentation. If there is no improvement on this, can you reopen the issue so we can include it in our roadmap? Please don't forget to add your feedback as a comment after reopening the issue. These will be taken into account by us and will contribute to the development of this feature. Thanks a lot for your understanding!
Best Regards,
I've opened Add multi-column feature to AutoComplete #13893