There is a contact form on wordpress, This jQuery makes the send button unavailable until the data is filled in, how to make a mask, the minimum number of digits when filling in, I use 2 fields, name and tel
jQuery(document).ready(function($){
$('.wpcf7-form').each(function () {
let form = $(this);
$(form).find('input[type=submit]').prop('disabled', true);
});
$(document).on('keyup', '.wpcf7-form input', function () {
let form = $(this).parents('.wpcf7-form');
let err = 0;
$(form).find('.wpcf7-form-control').not('input[type=submit]').each(function () {
if ($(this).val() == '') {
err++;
}
})
if (err > 0) {
$(form).find('input[type=submit]').prop('disabled', true);
}else{
$(form).find('input[type=submit]').prop('disabled', false);
}
})
})
Nothing is working out yet
2
Answers
Just use
<input type="tel">
as input for the telephone number. Then add therequired
attribute to that input.required
will only allow the submission of the form if all required fields are filled. If one of the required fields is not filled, the form will throw an error by default:To be sure that you are using the right element in loop, you rather use a var and set the value with
$(this)
. Even more when you loop inside an event.To get the correct value of input text, you need to use trim function that will remove empty space.
I commented my code.