symfony 1.4 动态添加表单小部件而不使用嵌入表单
我有一个 symfony 表单,我需要通过 jquery 动态添加几个字段(小部件)。假设我有一个用户表单,我希望用户能够设置多个电子邮件地址,
“电子邮件”只是一个简单的小部件,而不是一个表单,因此使用嵌入表单,就像网上提供的大多数教程一样,没有意义。
对此最好的方法是什么?
I have a symfony form and i need to add a couple of fields(widgets) dynamicly via jquery. Let´s say i have an User form and I want the user to be able to set multiple emails addresses,
The "email" is just a simple widget and not a form so using embeded forms ,like most of the tutorials avaliable in the net, doesn´t make sense.
What is the best approach to this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
建议的方法是使用嵌入式表单,但我发现这对您没有用(假设表单输入是通过 Javascript 添加的)。
我建议的一个解决方案(同时渴望看到其他人如何解决这个问题)是从小部件架构中删除
电子邮件
字段并仅添加它 到您的验证模式(使用自定义回调)。未经测试,但作为指导。
您的模板中将包含该字段(手动是的)。
我仍然希望看到其他人的建议,因为这对我来说也看起来很黑客。
The suggested way would be to use the embedded form, but I see how that could not be useful to you (given the form inputs are added via Javascript).
One solution I suggest (while eager to see how other people would solve this) is to remove the
email
field from the widget schema and only add it to your validation schema (with custom callback).Not tested but something along the lines as a guide.
And you would have in your template the field (manually yes).
I would still like to see others suggestion, because this looks hackish to me as well.