Skip to content

Instantly share code, notes, and snippets.

@dossy
Last active October 29, 2022 14:01
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dossy/9e9305ca32a6b7dcffad3b8b8f022878 to your computer and use it in GitHub Desktop.
Save dossy/9e9305ca32a6b7dcffad3b8b8f022878 to your computer and use it in GitHub Desktop.
Disable submit buttons on Gravity Forms when required fields are empty
<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