Last active
October 29, 2022 14:01
-
-
Save dossy/9e9305ca32a6b7dcffad3b8b8f022878 to your computer and use it in GitHub Desktop.
Disable submit buttons on Gravity Forms when required fields are empty
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
// don't forget to add a style for: | |
// `input[type="submit"].disabled, input[type="submit"].button-disabled, input[type="submit"]:disabled` | |
jQuery(function ($) { | |
$('form[id^="gform_"]').on('change', function (e) { | |
var $reqd = $(this).find('.gfield_contains_required.gfield_visibility_visible').filter(function (i, c) { | |
return [] | |
.concat($(c).find('input[type="text"], textarea').filter(function (i, fl) { return $(fl).val().length == 0; }).get()) | |
.concat($(c).find('input[type="checkbox"]').not(':checked').get()) | |
.length; | |
}); | |
if ($reqd.length) { | |
$(this).find('input[type="submit"]').addClass('disabled button-disabled').attr('disabled', 'disabled'); | |
} else { | |
$(this).find('input[type="submit"]').removeClass('disabled button-disabled').removeAttr('disabled'); | |
} | |
}).trigger('change'); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment