使用Rails和Cocoon将表单字段值传递给partial

时间:2016-11-11 21:00:20

标签: jquery ruby-on-rails ruby-on-rails-5 cocoon-gem

我使用Rails 5和Cocoon 1.2.9。我尝试创建一个包含单行输入字段和一个添加按钮的表单。当"添加"单击按钮并创建相关项目,新项目将动态添加到表格中。 Dynamic Table

我以为我可以通过link_to_add_association上的Cocoons渲染选项传递值,但我还没有能够获取字段值并将它们转换为locals传递给partial。它甚至可能吗?

我还尝试使用cocoon:before-insert在JavaScript中捕获值,但我再次不确定如何将捕获的字段值传递给cocoon可以使用的内容。

我可以用jQuery / cocoon询问什么,或者有更好的解决方案吗?

这是我尝试从插入前的静态表单元素中捕获输入值,但是,如果可能的话,如何将它们传递给cocoon以进行实际插入?

$(document).ready ->
  $('#order-items').on 'cocoon:before-insert', ->
    # This should capture the form field values...
    v_area = $('#order_v_area').val()
    v_product = $('#order_v_product').val()
    v_quantity = $('#order_v_quantity').val()
    v_comment = $('#order_v_comment').val()
    return
  return

0 个答案:

没有答案