0
I have this code that validates a form if it has several fields but it does the form Submit:
$("#btnAdd").click(function (e) {
e.preventDefault();
var erros = 0;
$("#formAdd input").each(function () {
$(this).val() == "" ? erros++ : "";
});
$("#formAdd textarea").each(function () {
$(this).val() == "" ? erros++ : "";
});
if (erros > 0) {
$("#msg").show().fadeIn(500).delay(1500).fadeOut(600);
} else {
$(this).submit(function () {
var form = $(this);
var dados = new FormData($(this)[0]);
$("#btnAdd").prop("disabled", true);
$.ajax({
url: 'u/add',
cache: false,
contentType: false,
processData: false,
data: dados,
type: 'post'
}).done(function (data) {
fetchUser();
alert("Dados Salvos com Sucesso");
console.log("STATUS : ", data);
$("#btnAdd").prop("disabled", false);
$('#modalAddfoto').modal('hide');
$('.addfoto')[0].reset();
}).fail(function (jqXHR, textStatus) {
console.log("Request failed: " + textStatus);
$("#btnAdd").prop("disabled", false);
});
return false;
});
}
});
it valid normal but is not entering this part of the code:
$(this).submit(function () { ... }
Detail, if I take the validation and do $('#formAdd').submit(function () { ... }
works normally.
this
in this context is referencing the #btnAdd and not the form– Alvaro Alves
this is not referencing the form
– Ademilson Santana da Silva
If I put
#formAdd
which is the form also does not work.– JB_
He gets into Isis?
– Ademilson Santana da Silva
Enters normal in Else.
– JB_