gform_input_mask_script

Description

Use this filter to change the initialization script for the input mask script. Can be used to specify different initialization parameters.

Usage

add_filter( 'gform_input_mask_script', 'set_mask_script', 10, 4 );

To target a specific form append the form id to the hook name. (format: gform_input_mask_script_FORMID)

add_filter( 'gform_input_mask_script_6', 'set_mask_script', 10, 4 );

Parameters

  • $script string
    The script to be filtered.
$script = "jQuery('#input_{$form['id']}_{$field->id}').mask('" . esc_js( $mask ) . "').on('keypress', function(e){if(e.which == 13){jQuery(this).blur();} } );";
  • $form_id integer
    ID of current form.
  • $field_id integer
    ID of current field.
  • $mask string
    Currently configured mask retrieved from $field->inputMaskValue.

Examples

This example changes the placeholder character to a blank space (” “)

add_filter( 'gform_input_mask_script_185', 'set_mask_script', 10, 4 );
function set_mask_script( $script, $form_id, $field_id, $mask ) {
    $script = "jQuery('#input_{$form_id}_{$field_id}').mask('" . esc_js( $mask ) . "',{placeholder:' '}).on('keypress', function(e){if(e.which == 13){jQuery(this).blur();} } );";
 
    return $script;
}

A full list of available initialization options can be found at:

https://github.com/digitalBush/jquery.maskedinput

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

gf_apply_filters( 'gform_input_mask_script', $form['id'], $script, $form['id'], $field->id, $mask );


This filter is located in GFFormDisplay::get_input_mask_init_script() in form_display.php