$(document).ready(function() {
    var max_fields = 20;
    var wrapper = $(".co-author-group");
    var add_button = $("#new-co-author");

    var x = 1;
    $(add_button).click(function(e) {
        e.preventDefault();
        if (x < max_fields) {
            x++;
            $(wrapper).append('<div class="form-group row"><div class="col-sm-3 mt-3"><label class="fieldlabels">Nome completo</label><input type="name" class="form-control" name="co_author_name[]" placeholder="Nome completo"></div><div class="col-sm-3 mt-3"><label class="fieldlabels">Email</label><input type="email" class="form-control" name="co_author_email[]" placeholder="Email"></div><div class="col-sm-2 mt-3"><label class="fieldlabels">Telefone</label><input type="text" class="form-control phone_with_ddd" name="co_author_phone[]" placeholder="Telefone"></div><div class="col-sm-3 mt-3"><label class="fieldlabels">Instituição</label><input type="text" class="form-control" name="co_author_company[]" placeholder="Instituição"></div><a href="#" style="height: 35px; margin-top: 3em;" class="btn btn-danger delete"><i class="fas fa-trash" style="height: 35px;"></i></a></div>'
            ); //add input box
            
        } else {
            alert('Limite máximo de co-autores');
        }
    });

      
    $(wrapper).on("click", ".delete", function(e) {
        e.preventDefault();
        $(this).parent('div').remove();
        x--;
    })
});