Skip to content

Instantly share code, notes, and snippets.

@richardW8k
Created November 14, 2013 16:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richardW8k/7470240 to your computer and use it in GitHub Desktop.
Save richardW8k/7470240 to your computer and use it in GitHub Desktop.
add an input mask to an input in a Gravity Forms list field column
// enable input mask for form #95 list field #3 columns 1 and 3
add_filter('gform_register_init_scripts_95', 'enable_list_input_mask');
function enable_list_input_mask($form) {
$field_id = "3"; //set field id here
$col_id = array('1','3'); //set column id here
$mask = "9999"; //define mask here, examples at http://www.gravityhelp.com/documentation/page/Input_Mask
//that's it nothing more to configure
$c_sel = array();
foreach($col_id as $c) {
$c_sel[] = ".gfield_list_{$field_id}_cell{$c} input";
}
$c_sels = json_encode($c_sel);
$im_script = "jQuery(sel.join()).mask('{$mask}');";
$script = "var sel = {$c_sels}; {$im_script} jQuery('#field_{$form["id"]}_{$field_id}').on('click', '.add_list_item', function(){{$im_script}});";
GFFormDisplay::add_init_script($form['id'], 'list_input_mask', GFFormDisplay::ON_PAGE_RENDER, $script);
return $form;
}
add_action( 'gform_enqueue_scripts_95', 'list_masked_input_script', 10, 2 );
function list_masked_input_script( $form ) {
wp_enqueue_script( 'gform_masked_input', array( 'jquery' ), false, true );
}
@brettg88
Copy link

Hello, I'm in the same boat as @ByteOutfitters. I have two list item fields and tried the same solution he did by separating out the two filters, but the input mask only applies to the first filter. Was there ever a solution for this?

Thanks!

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