Disable backend validation for choice field in Symfony 2 Type

后端 未结 3 1143
悲哀的现实
悲哀的现实 2021-01-02 01:05

Is it possible to disable backend (server-side) validation for the specified field?

Wnen Im trying to send form with dynamicly loaded options I get error \"ERROR: T

3条回答
  •  孤城傲影
    2021-01-02 01:49

    It's confusing but this behaviour is not really validation related as it is caused by the "ChoiceToValueTransformer" which indeed searches for entries in your pre-declared list. If your list is empty or you want to disable the transformer you can simply reset it.

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('yourField', 'choice', array('required'=>false));
    
        //more fields...
    
        $builder->get('yourField')->resetViewTransformers();
    }
    

    Then your custom defined validation will step in (if it exists).

提交回复
热议问题