结合 jquery 手风琴和 Rails 嵌套形式

发布于 2024-09-10 02:41:26 字数 799 浏览 10 评论 0原文

我想生成一个具有嵌套对象形式的表单,如下所示(在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

美人迟暮 2024-09-17 02:41:26

承认失败,我决定放弃嵌套形式并保留手风琴。所以,如果有人感兴趣,现在我这样做:

%div.children_accordion
  - @parent.children.each do |child|
    %h3
      %a{ :href => "#"}Header
    %div
      - form_for child do |child_form|
        -# etc.

这不是一个悲剧性的选择。事实上,如果我想允许 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:

%div.children_accordion
  - @parent.children.each do |child|
    %h3
      %a{ :href => "#"}Header
    %div
      - form_for child do |child_form|
        -# etc.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文