SymfonyCasts / dynamic-forms

Add dynamic/dependent fields to Symfony forms
https://symfonycasts.com
MIT License
98 stars 10 forks source link

Problem with autocomplete field #16

Open lgeorgiev opened 10 months ago

lgeorgiev commented 10 months ago

Hello,

Happy New Year!

When I use autocomplete=true, it selects the last element from the select element. I think it sometimes works correctly when I use the autocomplete=true option. When I removed autocomplete it worked as expected.

->addDependent('exercise', ['goalType'], function (DependentField $field, ?GoalType $goalType) {
    if (!$goalType || $goalType->value == GoalType::BodyWeight->value) {
        return;
    }
    $field->add(EntityType::class, [
          'required' => true,
          'class' => Exercise::class,
          'choice_label' => 'name',
          'empty_data' => null,
          'placeholder' => '',
          'autocomplete' => true,
    ]);
})

What could be the reason?

rvmourik commented 10 months ago

Hello,

Happy New Year!

When I use autocomplete=true, it selects the last element from the select element. I think it sometimes works correctly when I use the autocomplete=true option. When I removed autocomplete it worked as expected.

->addDependent('exercise', ['goalType'], function (DependentField $field, ?GoalType $goalType) {
    if (!$goalType || $goalType->value == GoalType::BodyWeight->value) {
        return;
    }
    $field->add(EntityType::class, [
          'required' => true,
          'class' => Exercise::class,
          'choice_label' => 'name',
          'empty_data' => null,
          'placeholder' => '',
          'autocomplete' => true,
    ]);
})

What could be the reason?

Are you by any chance rendering this form in a live component? I have the same issue but only when rendering it through a live component. So I think the issue is not related to this bundle but the combination of Live Components and the Autocomplete package.

See https://github.com/symfony/ux/issues/1261

lgeorgiev commented 10 months ago

Yes, I am using the form in Live Component because of the real-time validation and dependent form fields. Thanks for the link!