Symfony仅阅读复选框检查
我正在寻找一种禁用文本输入验证的方法,并在检查框时阅读文本类型?
$formBuilder
->add('text', TextType::class,array(
'required' => true,
'constraints' => array(
new NotBlank()
)))
->add('box', CheckboxType::class, array(
'mapped' => false,
'label' => 'Box'
))
;
I'm looking for a way to disable text input validation and readOnly the TextType if the box is checked?
$formBuilder
->add('text', TextType::class,array(
'required' => true,
'constraints' => array(
new NotBlank()
)))
->add('box', CheckboxType::class, array(
'mapped' => false,
'label' => 'Box'
))
;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将
EventListener
添加到您的FormBuilder,并基于输入数据添加约束。阅读有关动态形式修改的更多信息在这里。未经测试,但也许是这样的:
请记住,这只会进行服务器端验证,而不是前端。
You'll need to add an
eventListener
to your formBuilder and add constraints based on input data. Read more about dynamic form modification here.Not tested but maybe something like this:
Keep in mind that this will only do server side validation, not frontend.