Validate Minimum Limit Only When Field is Required

Only validate minimum limit when field is required or when at least one checkbox has been checked.

Code

Filename: gplcb-validate-minimum-limit-when-required.php

<?php
/**
 * Gravity Perks // Limit Checkboxes // Validate Minimum Limit Only When Field is Required
 * https://gravitywiz.com/documentation/gravity-forms-limit-checkboxes/
 *
 * Only validate minimum limit when field is required or
 * when at least one checkbox has been checked.
 */
add_filter( 'gplcb_should_validate_minimum', function( $should_validate, $form, $field ) {
	return $field->isRequired || gp_limit_checkboxes()->get_checkbox_count( $field->id, $form );
}, 10, 3 );

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.