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
Template for selected item in autocomplete (single selection mode) #2242
Comments
This should be fixed in recent PrimeNG release, please try with it and if the issue persists drop a comment with along with a test case based on plunkr below and we'll review again. |
@cagataycivici : I can still reproduce this issue starting from the Plunkr you provided (this uses PrimeNG 4.1.0.RC2 if I'm correct): |
Ok reopening then to be reviewed. Thanks. |
Is this planned for a new milestone? |
I'd also like this functionality. |
I also need this functionality |
Any news on this? Recent install, and still running against this issue. Tho it is documented in the spec: https://www.primefaces.org/primeng/#/autocomplete |
In single mode, there is an input so can't think of a way to use the selectedItemTemplate and the input at the same time so that's why it was closed I guess. Not sure how we can offer templating for the value prop of the input field. |
@cagataycivici : I don't understand what you mean by your last comment. Is something unclear about my initial question? |
I also need this functionality |
I need this functionality too. |
@cagataycivici I've implemented templating before using contenteditable="true" on a div. I did this in AngularJS using uib-typeahead. Unfortunately the new Angular implementations all require the selector on an "input" which makes this difficult. I'm hoping PrimeNG can implement it so it uses a |
Workaround using conversion method: Lets say we have a User type:
Use:
And in Component:
|
Workaround works, thanks. I notice a mismatch between code and documentation... In the documentation 'field' is declared as 'any'.
In AutoComplete component, 'field' attribute is declared as 'string'.
This needs to be clarified. |
@flix- can you provide a stackblitz with the workaround? [field] conversion doesn't seem to work. |
Same issue with angular 8. also related the attribute field can only be of type string. If it's a number it gives following error: ERROR TypeError: itemValue.trim is not a function |
@cagataycivici We also need this functionality. A very bad workaround with a weird flickering: @ViewChild('inputSearchTerm', {static: false}) inputSearchTerm: AutoComplete;
_searchTerm: string;
onSelectItem(item: any): void {
this.inputSearchTerm.inputEL.nativeElement.value = this._searchTerm;
} |
Hi all, |
Any update on this issue? |
I stumbled across this issue and found that the conversion method still works. As described by @ben12 it is just a compiler error as the autocomplete component declares the field input as string. You can force angular to ignore this template error by surrounding the variable with $any:
This actually works fine for me using primeng 12.2.2 and Angular 12.2. |
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? Best Regards, |
@mertsincan thanks! |
It still doesn't work. |
This issue is not solved. I need this functionality as well. |
This is still an issue after all those years. Should be reopened. Workarounds don't seem to work. I'm on Angular 15 and PrimeNG 15. |
Is there any progress? I have the same issue and the workarounds do not work. Can also the documentation be extended so the devs know that the selectItem template only works for multiple but not single selection mode. |
Same problem. At least the doc could be explicit |
Still an issue in v16 |
still an issue in v17, selectedItem Template is not working |
I'm submitting a ... (check one with "x")
Current behavior
It's already possible to define an "item" template for the suggestions of the autocomplete, but this template is not used for the selected item. The selected item only looks at the "field" attribute, so it can only display 1 property of the object to which the ngModel is bound.
It's also possible to define a "selectedItem" template, but this template only seems to work in multiple selection mode (as stated in the documentation).
I've tried this example:
With this code my selected item only shows the "name" property of my customer-object. If I don't provide the field-property, my selected item is displayed as [object Object].
Expected behavior
I expect it to be possible to define a template for the selected item when the autocomplete is in single selection mode. It seems like I'm missing something as no one else seems to be asking this question, but I've tried everything I could find in the documentation, and nothing seemed to work.
Minimal reproduction of the problem with instructions
The text was updated successfully, but these errors were encountered: