Last active
December 28, 2015 16:29
-
-
Save richardW8k/7529522 to your computer and use it in GitHub Desktop.
Activate input masks for List Field columns.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How do I have to active this input mask? Where do I have to add this code?