Skip to content

Instantly share code, notes, and snippets.

@richardW8k
Last active December 28, 2015 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richardW8k/7529522 to your computer and use it in GitHub Desktop.
Save richardW8k/7529522 to your computer and use it in GitHub Desktop.
Activate input masks for List Field columns.
add_filter('gform_enqueue_scripts_11', 'list_columns_mask_script');
function list_columns_mask_script() {
wp_enqueue_script( 'gform_masked_input', array( 'jquery' ), false, true );
}
add_filter('gform_register_init_scripts_11', 'list_columns_mask_init');
function list_columns_mask_init( $form ) {
$init = "";
/**
* Add a function call for each list field column you want to activate an input mask for
* $init .= "ListFieldMaskedInput( formId, fieldId, column, 'mask' );";
* $init .= "ListFieldMaskedInput( 11, 2, 1, '9999' );";
* for examples of input masks see http://www.gravityhelp.com/documentation/page/Input_Mask
*/
$init .= "ListFieldMaskedInput( 11, 1, 2, 'aaaa' );";
$init .= "ListFieldMaskedInput( 11, 2, 1, '9999' );";
/** Add your function calls above, nothing to edit below. */
$script = "function ListFieldMaskedInput( formId, fieldId, column, mask ){ jQuery( '.gfield_list_' + fieldId + '_cell' + column + ' input' ).mask( mask ); jQuery( '#field_' + formId + '_' + fieldId ).on( 'click', '.add_list_item', function(){ jQuery( '.gfield_list_' + fieldId + '_cell' + column + ' input' ).mask( mask ) });}";
GFFormDisplay::add_init_script( $form["id"], 'list_input_mask', GFFormDisplay::ON_PAGE_RENDER, $init . $script );
return $form;
}
@Createch5
Copy link

How do I have to active this input mask? Where do I have to add this code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment