<script>
$(function() {
const itemClass = '.product_movie_row';
const $body = $('#product_movie_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_movie').on('click',addForm);
$(document).on('click','#remove_product_movie',function() {
if(!confirm('削除しますか?')) {
return false;
}
const deleteIndex = $(this).data('index');
$(document).find('#product_movie_row'+deleteIndex).remove();
});
});
</script>