Description
The “gform_duplicate_field” JavaScript filter in Gravity Forms allows the field being duplicated in the Form Editor to be modified.
Usage
The following would apply to all field input types:
gform.addFilter('gform_duplicate_field', 'change_duplicate' );
To target a specific type of field, append the field input type (ie: text, select, radio) to the hook name. (format: gform_duplicate_field_FIELDTYPE)
gform.addFilter('gform_duplicate_field_text', 'change_duplicate' );
Parameters
- field Field Object
The Field Object.
-
form Form Object
The Form Object.
Example(s)
This example uses the gform_admin_pre_render filter to load the hook and set the label of the field being duplicated to ‘Duplicated Field’.
add_action( 'gform_admin_pre_render', 'add_duplicate_filter' ); function add_duplicate_filter( $form ) { ?> <script type="text/javascript"> gform.addFilter('gform_duplicate_field', 'change_duplicate' ); function change_duplicate( field, form ){ field.label = 'Duplicated Field'; return field; } </script> <?php return $form; }
Placement
Your code snippet should be placed in the functions.php file of your active theme when using it with the gform_admin_pre_render filter. Otherwise, you need to place the function in one of your theme’s JavaScript files which is included in the admin.
Since
Gravity Forms Version 2.2.2
Source Code
This filter is located in the StartDuplicateField() function in gravityforms/js/form_editor.js