删除一个字段的验证器约束

I'm currently wasting a lot of time doing a simple thing.

I want to remove the form checker/validator from symfony in a PARTICULAR field.

Adding this eventlistener to the builder work ok:

->addEventListener(
    FormEvents::POST_SUBMIT, 
    function (FormEvent $event) { 
        $event->stopPropagation(); 
    }, 
    900
)

But it disable the checker for ALL the field, and I only want for one field.

'required' => false and 'csrf_protection' => false don't do the trick

Any help thanks.

Constraints can come from many direction. From your question i am not sure from where the constraint you wanna get rid of come from.

  • AppBundle/Resources/validation.[yml|xml|php] look for your entity name and then the field name just comment/remove or modify the constraint if one is found.

  • The form type can apply constraint symfony doc if you have a constraint inside your type just open your EntityType.php class and look for the field name and check if there is a option for constraints

  • required options inside type and <input type="date"> can apply constraint on the client side so make sure it not that kind of constraint you wanna get rid of , you said you removed required but maybe a input type field persist.

  • And then you can have constraint apply inside event from a bundle your are using searching for the error message inside your source files can help you find the code responsible for that hidden constraint

A Symfony constraint should return a human readable error message on failure.

P.S. required is not a constraint but can look alike!