gform_editor_js_set_default_values

Description

The gform_editor_js_set_default_values action allows developers 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' );

Parameters

This hook has no parameters.

Examples

Change 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
}
>

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?

Source Code

This action is located in js.php.