Failed to call function with JavaScript parameter

0

I have the following function:

function show(msg, el){
    if(msg.alertType == 0){
    resetForm(el);
    setTimeout(function(){                  
        $('#show-toast').removeClass('toast-show');
        $('#show-toast .td.result .msg').remove();
    }, 5000);
    }else if(msg.alertType == 1){

    }etc..
}

function resetForm(form){
    if(form.length){
        form.trigger('reset');
        $(form).find("input[type='text']").each(function( index ) {
            if (!$(this).val())
                $(this).parent().removeClass('is-dirty , is-invalid');
        });
        $('.preview').find('img').attr('src', '#');
    }
}

if($('#form-blog').length){
    $('#enviar-post').click(function(e) {           
        var dados = new FormData($("#form-blog")[0]);
        var form = '#form-cursos';
        dados.append('action', 'insert-blog');

        $.ajax({
            url: 'database/actions.php',
            type: 'POST',               
            data: dados,
            processData: false,
            contentType: false
        })
        .done(function(rtv) {
            var data = JSON.parse(rtv);
            show(data, form);
            console.log("success");
        })
        .fail(function() {
            console.log("error");
        }).always(function(rtv) {
            $('#mdl-console').append(rtv);
        });
        return false;
    });
}

However, the resetForm(el) function of the error says that form is undefined

    
asked by anonymous 03.03.2017 / 14:56

1 answer

5

maybe

  

var form = '#form-cursos';

should be:

  

var form = $('#form-cursos');

    
03.03.2017 / 14:58