Skip to content
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

[LiveComponent] Undefined array key "placeholder" after upgrading to 2.22.x #2487

Open
maciazek opened this issue Jan 6, 2025 · 1 comment · May be fixed by #2491
Open

[LiveComponent] Undefined array key "placeholder" after upgrading to 2.22.x #2487

maciazek opened this issue Jan 6, 2025 · 1 comment · May be fixed by #2491
Labels
Bug Bug Fix LiveComponent Status: Reviewed Has been reviewed by a maintainer

Comments

@maciazek
Copy link

maciazek commented Jan 6, 2025

Hello,

recently after upgrading symfony/ux-live-components to 2.22.x I've encountered this exception:

An exception has been thrown during the rendering of a template ("Warning: Undefined array key "placeholder"").

Here's the reproducer: https://github.com/maciazek/symfony-ux-live-components-choices-reproducer

I have a custom DatalistType form field, which extends TextType to add HTML datalist into it. Inside DatalistType I'm using 'choices' option to add choices to datalist.
https://github.com/maciazek/symfony-ux-live-components-choices-reproducer/blob/master/src/Form/DatalistType.php#L11-L29
https://github.com/maciazek/symfony-ux-live-components-choices-reproducer/blob/master/templates/form/custom_types.html.twig

I have a form inside live component which is using DatalistType as a child field.
https://github.com/maciazek/symfony-ux-live-components-choices-reproducer/blob/ebe9ff77a7181ed6e0ca4dd5fca7483f38e8ed94/src/Form/ExampleType.php#L9-L30
https://github.com/maciazek/symfony-ux-live-components-choices-reproducer/blob/ebe9ff77a7181ed6e0ca4dd5fca7483f38e8ed94/src/Twig/Components/ExampleForm.php#L13-L23

Everything worked well until updating symfony/ux-live-components to 2.22.x - then I've encountered previously mentioned error.

After some investigation I've found that problem is caused by recent change in ComponentWithFormTrait:
https://github.com/symfony/ux-live-component/blob/5adf780aac0ccbd5cb1dddea683db9aa99b91d4a/src/ComponentWithFormTrait.php#L264-L271

I have 'choices' option in my DatalistType, but it's extending TextType which, as I guess, has no default values for placeholder, multiple and expanded options so they're missing in vars array.

Possible solutions:

  1. I can rename option 'choices' to something different, but I still haven't found a better name :)
  2. I can set default values for placeholder, multiple and expanded and assign them to vars inside buildView function in my DatalistType - that's my temporary workaround;
  3. Maybe these recently added vars tests could be null-coalesced or array_key_exists-ed in ComponentWithFormTrait?

Thank you for your great work on the whole UX ecosystem!

@maciazek maciazek added the Bug Bug Fix label Jan 6, 2025
@smnandre
Copy link
Member

smnandre commented Jan 7, 2025

Indeed, there should be a

&& \array_key_exists('placeholder', $child->vars)

before accessing the value.

Would you be ready to open a PR ?

@smnandre smnandre added Status: Reviewed Has been reviewed by a maintainer and removed Status: Needs Review Needs to be reviewed labels Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Bug Fix LiveComponent Status: Reviewed Has been reviewed by a maintainer
Projects
None yet
3 participants