I have a form and it has reputive / dynamic fields.. I want to show a popup if the required fields are empty.
It works only for one student / section. When you go here : https://jsfiddle.net/riffaz/7nrabcos/ click on the 'pay now' button. You will see popups for empty fields and the form won't be submitted..
but when you add another student using + sign button and submit the form without filling the 2nd student or section it will show the popup for that too.. but after that it submits the form right away..
I have no idea why..
jQuery
jQuery('#payBtn').on('click', function(event) {
event.preventDefault();
event.stopPropagation();
var formElement = jQuery(this).parents('form');
formElement.find('input:required').each(function() {
var minLength = 1;
var value = jQuery(this).val();
var checked = true;
if (value.trim().length < minLength) {
console.log('length is not ok');
checked = false;
}
if (!checked) {
console.log(jQuery(this).attr('name') + ' is not correctly filled!');
var alertMsg = jQuery(this).attr('name') + ' is not correctly filled!';
alert (alertMsg);
} else {
console.log('all is ok');
formElement.submit();
//jQuery('#myModal').modal('toggle');
}
});
})
And it is in WordPress
seems this one works : https://jsfiddle.net/1xk9gtvo/ but not work that in WordpPress.. I do not see any console errors..
I am so confusing..
How can I get this works on the WordPress site and what is wrong with my code?