1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

PrimeNG (16.9.15-lts) Autocomplete Bug: Selected Object Becomes String Instead of Object

Discussão em 'Angular' iniciado por devangelou, Outubro 1, 2024 às 08:02.

  1. devangelou

    devangelou Guest

    I am working on an Angular project that uses p-autoComplete to allow users to select a movie from a list. The autocomplete works well, but I’ve run into a strange issue.

    When a user selects a movie by typing the full title and clicking out of the field, the selectedMovie object is set correctly, and everything works as expected. However, if the user then focuses on the field again, deletes any character of the field, and then re-types the same character, when the user clicks out of the field, the selectedMovie variable is set to a string (the movie title) instead of the full Movie object.

    I set [forceSelection]="true" in the autocomplete component to ensure that only valid movie objects can be selected. I also checked the onBlur() method and logged the value of selectedMovie, expecting it to always contain the full Movie object, even after modifying the input. I have managed to replicate the bug into the following stackblitz,

    https://stackblitz.com/edit/wkppg3?file=src/app/demo/autocomplete-basic-demo.ts

    Continue reading...

Compartilhe esta Página