gform_conditional_logic_fields

Description

The gform_conditional_logic_fields JavaScript filter in Gravity Forms allows filtering which fields are available for conditional logic and adding custom fields to conditional logic.

Usage

gform.addFilter( 'gform_conditional_logic_fields', function( options, form, selectedFieldId  ) {
    // do stuff
  
    return options;
} );

Parameters

  • options array
    An array consisting of each conditional logic field with its label and field id.
  • form Form Object
    The current form.
  • selectedFieldId int
    The ID of the selected field.

Example

add_action( 'admin_print_scripts', function () {

  if ( method_exists( 'GFForms', 'is_gravity_page' ) && GFForms::is_gravity_page() ) { ?>
    <script type="text/javascript">
        gform.addFilter( 'gform_conditional_logic_fields', 'set_conditional_field' );
        function set_conditional_field( options, form, selectedFieldId ){
            if ( form.id == 121 ) {
              options.push( {
                 label: 'My Custom Field',
                 value: 5
              } );
           }
           return options;
        }
    </script>
  <?php }

} );

Placement

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

Since

This filter was added in Gravity Forms version 1.7.6.

Source Code

This filter is located in the function GetRuleFields() in gravityforms/form_admin.js