<script>
$(function() {
const itemClass = '.product_spec_row';
const $body = $('#product_spec_body');
let index = $body.find(itemClass).length;
function addForm() {
const prototype = $body.data('prototype');
const newForm = prototype.replace(/__name__/g, index);
$body.append(newForm);
index++;
}
$('#add_product_spec').on('click',addForm);
$(document).on('click','#remove_product_spec',function() {
if(!confirm('削除しますか?')) {
return false;
}
const deleteIndex = $(this).data('index');
$(document).find('#product_spec_row'+deleteIndex).remove();
});
});
</script>