10000 FormConfigBuilder::resetViewTransformers() broken for ChoiceType - Cannot add dynamic options anymore · Issue #42451 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
FormConfigBuilder::resetViewTransformers() broken for ChoiceType - Cannot add dynamic options anymore #42451
Closed
@jsfgreen

Description

@jsfgreen

Symfony version(s) affected: 4.4.20+

Description
Since bug #39659 was addressed in 4.4.20, a FormEvents::POST_SUBMIT listener was added to choice types with 'multiple' => true. This is causing the dynamic options that were added to be flagged as invalid and I cannot submit my form anymore. I am using JavaScript to dynamically add options which used to work just by calling:

public function buildForm(FormBuilderInterface $builder, array $options): void
{
    // ...
    $builder->get('my_field')->resetViewTransformers(); // allow dynamic options
}

But now I get

Symfony\Component\Form\Exception\TransformationFailedException {#2900 ▼
  -invalidMessage: null
  -invalidMessageParameters: []
  #message: "The choices "choice1" do not exist in the choice list."
  #code: 0
  #file: "....vendor/symfony/form/Extension/Core/Type/ChoiceType.php"
  #line: 186
  trace: {▶}
}

How to reproduce
Use JavaScript to dynamically add an <option> to your ChoiceType field (select dropdown) and submit.

Additional context
I've been stuck at 4.4.19 for a while now because of this. I thought it might get addressed in future releases which is why I waited to submit this bug.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0