结合 jquery 手风琴和 Rails 嵌套形式
我想生成一个具有嵌套对象形式的表单,如下所示(在 haml 中):
- form_for @parent do |parent_form|
- parent_form.fields_for :children do |child_form|
= child_form.label :first_name
= child_form.text_field :first_name
...并且我想将子表单放置在 jquery ui (1.8.2) 手风琴中,如下所示(我认为):
- form_for @parent do |parent_form|
%div#accordion
- parent_form.fields_for :children do |child_form|
%h3
%a{ :href => "#" }Header
%div
-# I wish this was a content div
= child_form.label :first_name
= child_form.text_field :first_name
这几乎可以工作,但是 fields_for 在每个子“迭代”的末尾插入一个隐藏输入。此输入是作为内容 div 的同级生成的,这使 jquery ui 感到困惑。看起来 Accordion() 错误地将隐藏输入作为下一个标头,事情从那里开始变得混乱。
如果有人能告诉我如何将嵌套表单放入 jquery ui 手风琴中,我将非常感激。
罗格兹,丹
I'd like to generate a form with nested object forms like this (in haml):
- form_for @parent do |parent_form|
- parent_form.fields_for :children do |child_form|
= child_form.label :first_name
= child_form.text_field :first_name
... and I'd like to place the child forms in a jquery ui (1.8.2) accordion, like this (I think):
- form_for @parent do |parent_form|
%div#accordion
- parent_form.fields_for :children do |child_form|
%h3
%a{ :href => "#" }Header
%div
-# I wish this was a content div
= child_form.label :first_name
= child_form.text_field :first_name
This nearly works, but fields_for inserts a hidden input at the end of each child "iteration". This input is generated as a sibling to the content div, which confuses jquery ui. It seems accordion() mistakes the hidden input for the next header, and things get jumbled from there.
I'd be much obliged if someone could tell me how to put nested forms into a jquery ui accordion.
Rgds, Dan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
承认失败,我决定放弃嵌套形式并保留手风琴。所以,如果有人感兴趣,现在我这样做:
这不是一个悲剧性的选择。事实上,如果我想允许 ajax 发布对象的组成部分,它比大的、包罗万象的形式要优越。
Conceding defeat, I've decided to abandon the nested form and keep the accordion. So, in case anyone is interested, now I do this:
Which isn't a tragic alternative. In fact, it's superior to the big, all-inclusive form if I want to allow ajax posts of the object's component parts.