我的表单中有多个字段,如姓名,姓氏,电子邮件等。 我想添加新行/想要删除不需要的行,而不是单个行但是 行的整个组合 像
1. name "textbox" email "textbox" "link-addmore"=========== "link-remove"
2. name "textbox" email "textbox" "link-addmore"=========== "link-remove"
.
.
.
我尝试过rails cast,它适用于非单个字段但不适用于所有字段的组合 如果我想要应用整个组合,我应该怎么做
修改 .js文件
function remove_fields(link) {
$(link).previous("input[type=hidden]").value = "1";
$(link).up(".fields").hide();
}
function add_fields(link, association, content) {
var new_id = new Date().getTime();
var regexp = new RegExp("new_" + association, "g")
$(link).up().insert({
before: content.replace(regexp, new_id)
});
}
module ApplicationHelper
def link_to_remove_fields(name, f)
f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this)")
end
def link_to_add_fields(name, f, association)
new_object = f.object.class.reflect_on_association(association).klass.new
fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder|
render(association.to_s.singularize + "_fields", :f => builder)
end
link_to_function(name, "add_fields(this, \"#{association}\", \"#{escape_javascript(fields)}\")")
end
end