gform_field_choice_selected_type_form_editor

Description

The “gform_field_choice_selected_type_form_editor” JavaScript filter in Gravity Forms allows the “input type” for choices (checkbox, radio) to be overridden. This hook is used when custom types have been created and will only be needed with such a special case.

Usage


gform.addFilter( 'gform_field_choice_selected_type_form_editor', function( type, field ) {
    // do stuff
 
    return type;
} );

Parameters

  • type string

    The choice selected input type. Defaults to checkbox for checkbox type fields or radio for other field types.

  • field Field Object

    The current field.

Example

add_action( 'gform_admin_pre_render', 'set_choice' );
function set_choice( $form ) {
    ?>
    <script type="text/javascript">
        gform.addFilter('gform_field_choice_selected_type_form_editor', 'set_choice');
        function set_choice(type, field){
            if ( field.id == 1 ){
            	type = 'radio';
            }
            return type;
        }
    </script>
    <?php
    //return the form object from the php hook
    return $form;
}

Placement

Your code snippet should be placed in the functions.php file of your active theme.

Source Code

This filter is located in the function GetFieldChoices() in gravityforms/js.php