Description
Allows setting the maximum number of choices shown in the form editor for choice based fields (Radio Buttons, Checkbox, Image Choice, and Multiple Choice).
Usage
add_filter( 'gform_field_choices_max_count_visible', 'your_function_name', 10, 2 );
Parameters
- $max_choices_visible_count string
The default number of choices visible is 5. - $field object
The current field object
Examples
Sets the maximum choices shown in the form editor to 1 for all choice based fields.
add_filter( 'gform_field_choices_max_count_visible', function( $max_choices_visible_count, $field ) {
return 1;
}, 10, 2 );
Sets the maximum choices shown in the form editor for the Image Choice fields to 1 and keeps the default for Radio Buttons, Checkbox, and Multiple Choice fields.
add_filter( 'gform_field_choices_max_count_visible', function( $max_choices_visible_count, $field ) {
if ( $field['type'] === 'image_choice' ) {
return 1;
}
return $max_choices_visible_count;
}, 10, 2 );
Placement
This code can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.
See also the PHP section in this article: Where Do I Put This Code?
Since
This filter was added in Gravity Forms 2.9.
Source Code
This filter is located in includes/fields/class-gf-field-checkbox.php, includes/fields/class-gf-field-radio.php, includes/fields/class-gf-field-decorator-checkbox-markup.php, includes/fields/class-gf-field-decorator-radio-markup.php