根据选择的值的Symfony 2 dynamiclly变化形式根据、形式、Symfony、dynamiclly

2023-09-10 16:17:56 作者:长虹饮涧

我有以下表格:

Events:
 - Date (date)
 - EventType (varchar)
 - Value (varchar)

事件类型可以有几个值即签,签出,roomrent,杂项等。我想使形式将根据在事件类型选择的类型改变价值字段类型为文本,日期或实体。我试图找到一些解决方案,但没有成功。 The我唯一​​发现的,我不得不使用的QueryBuilder但真正能抓到怎么办呢。

EventType can have a few values i.e checkin, checkout, roomrent, misc etc. I want to make form which will change field type of "Value" to text,date or entity based on selected type in "EventType". I tried to find some solutions but didn't succeed. The only thing I found that I have to use queryBuilder but really can catch how to do it.

推荐答案

您应该使用事件订阅,添加一个事件订户表单,你委托创作的领域给该用户的。 在你的事件订阅你可以检查你的事件类型,并添加相应的值字段。

You should use Event Subscribers, by adding an event subscriber to your Form, you delegate the creation of your fields to that Subscriber. Inside your Event Subscriber your could check your "EventType" and add the appropriate "Value" field.

如何动态生成表单使用表格活动

Adding事件用户到窗体类