Description
This action hook can be used to inject Javascript into the form editor page.
Usage
add_action( 'gform_editor_js', 'editor_script' );
Examples
1. Basic example
add_action( 'gform_editor_js', 'editor_script' ); function editor_script(){ echo '<script type="text/javascript">//do something</script>'; }
2. Adding a custom setting to all field types
This example adds a custom setting, which has been implemented using gform_field_standard_settings, gform_field_appearance_settings, or gform_field_advanced_settings, to the fields.
add_action( 'gform_editor_js', function () { echo '<script type="text/javascript">' . PHP_EOL; foreach ( GF_Fields::get_all() as $gf_field ) { echo 'fieldSettings.' . $gf_field->type . ' += ", .encrypt_setting";' . PHP_EOL; } echo '</script>' . PHP_EOL; } );
3. Set default date format
This example sets the default date format for date type fields to dmy_dot.
add_action( 'gform_editor_js', function () { echo '<script type="text/javascript">function SetDefaultValues_date(field){field.dateFormat = "dmy_dot";}</script>' . PHP_EOL; } );
Source Code
This filter is located in js.php.