-
-
Notifications
You must be signed in to change notification settings - Fork 370
Description
Hi, I have a form with a ChoiceType
field like this:
->add('my_choices', ChoiceType::class, [
'multiple' => true,
'expanded' => true,
'choices' => [
'foo' => 'foo',
'bar' => 'bar',
'baz' => 'baz',
],
'choice_attr' => fn($choice) => 'foo' === $choice ? ['disabled' => true] : [],
'constraints' => [
new Choice(['bar', 'baz'], multiple: true),
],
])
as you can see, the foo
choice is disabled, so it can not be selected and this is validated on the backend.
I use this form in a live component something like this:
#[AsLiveComponent('my_form')]
final class MyForm
{
use DefaultActionTrait;
use ComponentWithFormTrait;
protected function instantiateForm(): FormInterface
{
return $this->createForm(MyType::class, ['my_choices' => ['foo']]);
}
}
the foo
option is selected by default (but it will be disabled when the form is rendered). If I update the form and select an another choice from the list, a live update is triggered and the form is validated, but it gives back that the foo option is invalid, but then I post the form regularly (click the submit button) the validation passes because the browser does not send disabled checkbox values to the backend, but live components kind of does. We should somehow know that the foo
choice is disabled and ignore when updating, but keep it's original selected state.