【发布时间】:2020-11-06 08:42:56
【问题描述】:
我的 Symfony 4 应用程序中有一个表单。我有 2 个字段,一个 ChoiceType 和一个 TextType。如果在 ChoiceType 中选择了“其他”选项,是否可以启用 TextType,如果选择了其他选项,是否可以禁用?
这是我目前的表格:
$builder
->add('colour', ChoiceType::class, [
'choices' => [
'Red' => 0,
'Green' => 1,
'Blue' => 2,
'Other' => 3
],
'mapped' => false,
'label' => 'What is your preferred colour?',
'required' => false
])
->add('colour_other', TextType::class, [
'mapped' => false,
'label' => 'Please specify:',
'required' => false,
'disabled' => true
])
;
我想使用 Symfony 表单构建器来实现这一点,或者我需要编写一些自定义 javascript?
【问题讨论】:
-
也许你可以在这里找到一些有用的信息:symfony.com/doc/current/form/events.html#event-listeners
标签: symfony