Allow to add a new value in a choice Field Type

后端 未结 3 1591
名媛妹妹
名媛妹妹 2021-02-05 15:20

I use Form Component and have a choice Field Type on a form which is rendered to a select field. On a client-side I use select2 plugin which initializes the select with the sett

3条回答
  •  太阳男子
    2021-02-05 15:41

    The problem is in a choice transformer, which erases values that don't exist in a choice list.
    The workaround with disabling the transformer helped me:

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('choiceField', 'choice', ['choices' => $someList]);
    
        // more fields...
    
        $builder->get('choiceField')->resetViewTransformers();
    }
    

提交回复
热议问题