Skip to content

Commit a0a7905

Browse files
committed
gw-force-numeric-keyboard-on-mobile.php: Added support for Number fields using the decimal-comma and currency formats.
1 parent 872577b commit a0a7905

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

experimental/gw-force-numeric-keyboard-on-mobile.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55
*
66
* This snippet forces the numeric keyboard for Number fields on mobile devices by updating the "type" attribute of the
77
* input to "tel" instead of "number". If you find there are any drawbacks to this approach, let us know!
8+
*
9+
* Known Limitations
10+
*
11+
* 1. This will not work if you're collecting decimal numbers as mobile numeric keyboards do not support decimals or commas.
812
*/
913
add_filter( 'gform_field_content', function( $content, $field ) {
1014
if ( $field->get_input_type() === 'number' ) {
11-
$content = str_replace( 'type=\'number\'', 'type=\'tel\'', $content );
15+
$content = preg_replace( '/type=\'(number|text)\'/', 'type=\'tel\'', $content );
1216
}
1317
return $content;
1418
}, 10, 2 );

0 commit comments

Comments
 (0)