gform_editor_js_set_default_values

Description

This action hook can be used to inject Javascript into the SetDefaultValues() function on the form editor page. Use this hook to define default field properties when creating new field types.

Usage

add_action( 'gform_editor_js_set_default_values', 'set_defaults' );

Examples

This example changes the default label for a new field type:

add_filter( 'gform_add_field_buttons', 'add_new_field' );
function add_new_field( $field_groups ) {
    //Adds a new field to the end of the standard fields list
    $field_groups[0]['fields'][] = array( "class"=>"button", "value" => 'My Field', "onclick" => "StartAddField('my_field_type');" );
    return $field_groups;
}

add_action( 'gform_editor_js_set_default_values', 'set_defaults' );
function set_defaults(){
    ?>
    //this hook is fired in the middle of a switch statement,
    //so we need to add a case for our new field type
    case "my_field_type" :
        field.label = "My Default Field Label"; //setting the default field label
    break;
    <?php
}

?>

Source Code

This filter is located in js.php.