2
我想在Symfony 3.0.9中定義一些ChoiceType,表單中填充了ajax,具體取決於動態創建了多少個選項,但驗證表單表示選擇的選項不是有效。Symfony ChoiceType初始化空白數組
我定義ChoiceType這樣的:
->add('position', ChoiceType::class, [
'placeholder' => 'Select position',
'choices' => [],
'attr' => [
'class' => 'form-control choice-position'
],
])
而我得到的錯誤是:
Symfony\Component\Validator\ConstraintViolation
Object(Symfony\Component\Form\Form).children[lessonGroups].children[0].children[position] = 1
Caused by:
Symfony\Component\Form\Exception\TransformationFailedException
Unable to reverse value for property path "position": The choice "1" does not exist or is not unique
Caused by:
Symfony\Component\Form\Exception\TransformationFailedException
The choice "1" does not exist or is not unique
,如果有需要的任何進一步的信息,我不知道。
謝謝!
你是什麼symfony的版本? – goto
您需要查看錶單事件 - http://symfony.com/doc/current/form/dynamic_form_modification.html – Rooneyl