duanbi9202 2017-01-26 14:34
浏览 28

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

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.

  • 写回答

1条回答 默认 最新

  • dongxian7489 2017-01-26 14:54
    关注

    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!

    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100