cs_app/app/assets/javascripts/nested_fields.coffee
Nicolas Bally 8a08ee35c8 initial
2015-02-22 14:36:30 +01:00

11 lines
434 B
CoffeeScript

@remove_fields = (link) ->
$(link).prev("input[type=hidden]").val "1"
$(link).closest(".field").hide()
false
@add_fields = (link, association, content) ->
new_id = new Date().getTime()
regexp = new RegExp("new_" + association, "g")
$(link).closest("p").next("." + association + "_form").prepend content.replace(regexp, new_id).replace(association + "_class", "new_field")
$(".new_field").removeClass "new_field"
false