Symfony EntityType - 提交后访问 choice_label
Symfony EntityType - access choice_label after submitting
我有一个 EntityType 字段:
->add('topic', null, [
'required' => false,
'class' => Category::class
])
对于新的 Category
,我的 js 工具创建了一个新的 select 选项,标有 __new_option__
:
所以读取的值不是值。就是标签。
提交后如何读取这个值。
我尝试了 addViewTransformer
、addEventListener
和 preSetData
以及 postSetData
。
但是当我得到值时 - 它每次只显示 __new_option__
而不是持久保存到数据库中的值。
有办法吗?
How can I read this value after submission. I tried
addViewTransformer, addEventListener with preSetData and postSetData.
由于 post-数据包含 topic
-字段方程'new_option'。 “它对所选值的标签一无所知”。
我不知道你的实现,但是 -> 只需更改修改提交时的 js 行为,例如:
let topicSelection = document.getElementById('SELECTOR');
topicSelection.options[el.selectedIndex].value = topicSelection.options[el.selectedIndex].innerHTML;
//... submitting
我有一个 EntityType 字段:
->add('topic', null, [
'required' => false,
'class' => Category::class
])
对于新的 Category
,我的 js 工具创建了一个新的 select 选项,标有 __new_option__
:
所以读取的值不是值。就是标签。
提交后如何读取这个值。
我尝试了 addViewTransformer
、addEventListener
和 preSetData
以及 postSetData
。
但是当我得到值时 - 它每次只显示 __new_option__
而不是持久保存到数据库中的值。
有办法吗?
How can I read this value after submission. I tried addViewTransformer, addEventListener with preSetData and postSetData.
由于 post-数据包含 topic
-字段方程'new_option'。 “它对所选值的标签一无所知”。
我不知道你的实现,但是 -> 只需更改修改提交时的 js 行为,例如:
let topicSelection = document.getElementById('SELECTOR');
topicSelection.options[el.selectedIndex].value = topicSelection.options[el.selectedIndex].innerHTML;
//... submitting