根据选择的值的Symfony 2 dynamiclly变化形式 [英] Symfony 2 dynamiclly change form based on selected value

查看:126
本文介绍了根据选择的值的Symfony 2 dynamiclly变化形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下表格:

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

事件类型可以有几个值即签,签出,roomrent,杂项等。我想使形式将根据在事件类型选择的类型改变价值字段类型为文本,日期或实体。我试图找到一些解决方案,但没有成功。 <一href="http://stackoverflow.com/questions/10004759/dynamic-form-with-multiple-choice-fields-symfony2">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.

<一个href="http://symfony.com/doc/current/cookbook/form/dynamic_form_generation.html#adding-an-event-subscriber-to-a-form-class">Adding事件用户到窗体类

这篇关于根据选择的值的Symfony 2 dynamiclly变化形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆