Submit of form with jquery

0

I have this function to check the state and CNPJ / CPF registration fields and if they are correct it performs submit , only in submit , it is not respecting the required of the fields entered in ViewModel

$('#FornecedorNovo').submit(function (e) {
    e.preventDefault();
    var url = "/Fornecedor/VerificaInscricao";
    var Insc = $("#InscricaoEstadual").val();
    var Tipo = $("#TipoPessoa").val();
    var Isento = $("#InscricaoIsento").prop('checked');
    var form = this,
        $form = $(form); // Salvamos o formulário atual em uma variável

    $.ajax({
        url: url,
        data: { insc: Insc, isento: Isento },
        datatype: "json",
        type: "POST",
        success: function (data) {
            if (data.resultado == true) {
                $("#messageI").html(data.mensagem);
                if (data.mensagem != 'O campo Inscrição é obrigatório.') {
                    $("#InscricaoEstadual").val('');
                    $("#InscricaoEstadual").focus();
                }
            } else {
                var url1 = "/Fornecedor/VerificaDocumento";
                var Documento = $("#Documento").val();

                $.ajax({
                    url: url1,
                    data: { documento: Documento, tipo: Tipo },
                    datatype: "json",
                    type: "POST",
                    success: function (data) {
                        if (data.resultado == true) {
                            $("#message").html(data.mensagem);
                            $("#Documento").val('');
                            $("#Documento").focus();
                        }
                        else {
                            $form.off('submit').submit();
                        }
                    }
                });
            }
        }
    })
});

Surely it would not be him to make the submit only if the fields were correct? Because if the field State Registration and Document are in agreement, it sends the data anyway.

    
asked by anonymous 03.10.2018 / 20:23

1 answer

0

I was able to resolve by adding this line in the submit part:

   if ($('#FornecedorNovo').valid()) {
         $form.off('submit').submit();
   }
    
03.10.2018 / 22:15