Primeng: Autocomplete with forceSelection, templates and objects causes 'itemValue.trim is not a function'

Created on 20 Aug 2018  Â·  13Comments  Â·  Source: primefaces/primeng

I'm submitting a ...

[x ] bug report => Search github for a similar issue or PR before submitting

Current behavior
When using an autocomplete control with:

  • forceSelection=true
  • the suggestions being objects and not strings
  • a template for the items in the suggestion list
  • a template for the selected item
    then an error occurs when typing a valid search string and selecting an item.

The error is: itemValue.trim is not a function

The error occurs in https://github.com/primefaces/primeng/blob/master/src/app/components/autocomplete/autocomplete.ts#L576 on line 576.

Expected behavior
No error.

Plunkr Case (Bug Reports)
(stackblitz not working)
http://embed.plnkr.co/DSUc1OoBOdHawTUi (to edit http://next.plnkr.co/edit/DSUc1OoBOdHawTUi)

Minimal reproduction of the problem with instructions
In the plunker:

  1. open up the console
  2. type "tom" in the input box
  3. click the suggestion
  4. the error ERROR TypeError: itemValue.trim is not a function should appear in the console

Please tell us about your environment:
OS: Win10,
IDE: VS Code,
Package manager: node + npm

  • Angular version: 5.X
    4.4.7 & 6.0.7 (plunker)

  • PrimeNG version: 5.X
    6.0.1 (the code in current version 6.1.3-SNAPSHOT is still the same) & 6.1.2 (plunker)

  • 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 ]
    Chrome 68.0.3440.106 (Official Build) (64-bit)

  • Language: [all | TypeScript X.X | ES6/7 | ES5]
    Typescript 2.6.2 compiled to ES5

Most helpful comment

Running into this again. Can this please be prioritized?

All 13 comments

I am seeing the same issue with Angular 6.1.2 and PrimeNG 6.1.0

Is there a known workaround for this? It is caused by this line.
It assumes if there is no field input present, that the suggestions are backed by an array of strings. That is not the case if we are using templates.

I use the field input binding as workaround.

On Fri, 7 Sep 2018, 23:30 rich4756, notifications@github.com wrote:

Is there a known workaround for this? It is caused by this
https://github.com/primefaces/primeng/blob/6.1.0/src/app/components/autocomplete/autocomplete.ts#L569
line. It assumes if there is no field input present, that the suggestions
are backed by an array of strings. That is not the case if we are using
templates.

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/primefaces/primeng/issues/6360#issuecomment-419571007,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ARNjJELon2JAEzFomPypoSJN076WRKWlks5uYuVygaJpZM4WECCs
.

Any updates on this? Also note that a side effect of this seems to be that the input isn't cleared, due to the error being thrown prior to isValid check.

Experiencing this issue as well. Bump

Me too :-/

Waiting for update :/ Only problem

Running into this again. Can this please be prioritized?

Has anyone been able to find a quick fix?

Having the same issue.

I use the field input binding as workaround.
…
On Fri, 7 Sep 2018, 23:30 rich4756, @.*> wrote: Is there a known workaround for this? It is caused by this https://github.com/primefaces/primeng/blob/6.1.0/src/app/components/autocomplete/autocomplete.ts#L569 line. It assumes if there is no field input present, that the suggestions are backed by an array of strings. That is not the case if we are using templates. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub <#6360 (comment)>, or mute the thread https://github.com/notifications/unsubscribe-auth/ARNjJELon2JAEzFomPypoSJN076WRKWlks5uYuVygaJpZM4WECCs .

Could you elaborate on this?

If you use forceSelection with objects then you need provide field property. Like this https://stackblitz.com/edit/github-yhhfjh .

If you use forceSelection with objects then you need provide field property. Like this https://stackblitz.com/edit/github-yhhfjh .

That does not solve the problem.

Was this page helpful?
0 / 5 - 0 ratings