I’m trying to use the action hook gform_field_advanced_settings to add a custom field (checkbox) to the Advanced tab for field types other than Single Line Text.
I tried the example supplied in the documentation here:
However, I don’t see the custom setting appear for any other field types (radio, choice, name, website, etc) besides Single Line Text.
I’ve tried nearly every integer possible for the $position parameter and no luck.
How do I go about adding custom settings to the Advanced tab for Standard and Advanced field types other than Single Line Text?
I submitted a support ticket for this and the support team helped me solve my problem.
Replying here for anyone else that might have this issue in the future.
The example code in the documentation for gform_field_advanced_settings was only adding the custom setting to the text field type in the callback for the gform_editor_js action.
In order to add the custom setting to other field types (radio, name, website, email, etc) you have to add to the appropriate field property names for the fieldSettings object in the callback for gform_editor_js.
Code below of modified example from gform_field_advanced_settings to achieve this:
<?php
//Action to inject supporting script to the form editor page
add_action( 'gform_editor_js', 'editor_script' );
function editor_script(){
?>
<script type='text/javascript'>
//Add setting to fields of type "text"
fieldSettings.text += ", .encrypt_setting";
//Add setting to fields of type "radio"
fieldSettings.radio += ", .encrypt_setting";
//Add setting to fields of type "name"
fieldSettings.name += ", .encrypt_setting";
//Add setting to fields of type "website"
fieldSettings.website += ", .encrypt_setting";
//Add setting to fields of type "email"
fieldSettings.email += ", .encrypt_setting";
//binding to the load field settings event to initialize the checkbox
jQuery(document).on("gform_load_field_settings", function(event, field, form){
jQuery( '#field_encrypt_value' ).prop( 'checked', Boolean( rgar( field, 'encryptField' ) ) );
});
</script>
<?php
}
?>
1 Like