Sha256: 4828f118078e7c123e0a2cf1d2a3721d237f4cd85dde0e22b98a7432a17c5379
Contents?: true
Size: 970 Bytes
Versions: 3
Compression:
Stored size: 970 Bytes
Contents
$(document).on("ready", function() { $(".add-fields").click(function(e) { e.preventDefault(); var count = $(this).attr("data-count"), type = $(this).data("type"), lastFields = $("." + type + "-fields:last"), newFields = lastFields.clone(); count++; newFields.find("input, select") .attr("name", function(i, val) { if(val) { return val.replace(/\d/, count) } }) .attr("id", function(i, val) { if(val) { return val.replace(/\d/, count) } }) .val([]); newFields.find("label").attr("for", function( i, val ) { return val.replace(/\d/, count) }); newFields.insertAfter(lastFields); $(this).attr("data-count", count); newFields.show(); }); $(".fields-for").on("click", ".remove-fields", function(e) { e.preventDefault(); var type = $(this).attr("data-type"), fields = $(this).parents("." + type + "-fields"); fields.find("input[identifier=destroy]").val("1"); fields.hide(); }); });
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
adeia-0.15.4 | app/assets/javascripts/adeia/nested_form.js |
adeia-0.15.3 | app/assets/javascripts/adeia/nested_form.js |
adeia-0.15.2 | app/assets/javascripts/adeia/nested_form.js |