0
Guys, I’m trying to do the following, when you click on the button it checks if the fields are empty, if it’s all filled it hides the form, the problem it’s not falling into else
of verification: if (formError) {...} else {...}
.
When the form is completed correctly it should fall into the else
.
Here is an excerpt from the code.
const fields = [...$('.form-group input')];
$.each(fields, function (index) {
if ($(this).val() === "") {
cardForm.removeClass('fadein').addClass('validate-error')
}
});
const formError = $('.validate-error');
if (formError) {
formError.bind('animationend', function (e) {
if (e.originalEvent.animationName === 'nono') {
formError.removeClass('validate-error').addClass('fadein');
}
});
} else {
cardForm.removeClass('fadein').addClass('form-hide');
}
Gosh, aoskoaksokas, Thank you bro, every time I want to check if there’s something I have to use
length > 0
?, but thank you very much brother– Boi Programador
@Boyprogrammer not necessarily, is that in this specific case, when you try to pull something with the jQuery selector, it will always return you a valid object, but if you have a variable/constant
undefined
, the check you tried to do would be correct. (:– Felipe Avelar
@Bull programmer Can do so too:
if (formError.length)
, because if it is greater than zero it will validate.– Sam
Ah got it, vlw guys
– Boi Programador