gplcb_should_validate_minimum

  1. Description
  2. Usage
  3. Parameters
  4. Since
  5. Examples
    1. Only validate minimum limit when field is required or when at least one checkbox has been checked.

Description

Filter whether the current field’s minimum limit be validated.

Usage

Apply to all fields on all forms.

add_filter( 'gplcb_should_validate_minimum', '__return_true' );

Apply to all fields on a specific form.

add_filter( 'gplcb_should_validate_minimum_FORMID', '__return_true' );

Apply to a specific field on a specific form.

add_filter( 'gplcb_should_validate_minimum_FORMID_FIELDID', '__return_true' );

Parameters

  • should_validate_min bool

    Should current field’s minimum limit by validated? Defaults to true.

  • form array

    The form object to which the current field belongs.

  • field \GF_Field

    The current Checkbox field.

Since

This filter is available since Gravity Forms Limit Checkboxes 1.3.1.

Examples

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

<?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 );