I would like to make entering data easier for my users who use the mobile version of my site. I've been searching around both Android and Drupal documentation and eventually found this: https://stackoverflow.com/questions/3372380/how-to-force-keyboard-with-numbers-in-mobile-website-in-android

Which says that using

<input type="number" />
<input type="tel" />

will bring up the number pad for the user.

I would like to figure out the best way to change all of my integer and decimal fields to have type="number".

I'm aware of doing a hook to do this but I have a lot of fields which are numbers and I was wondering if there was a more effective way to change ALL the fields rather that me writing a line for each of the fields. Maybe if I had an array of all the fields and then programically went through all the fields in the array?


1 Answer 1



Alter forms for field widgets provided by other modules.

or use hook_field_widget_WIDGET_TYPE_form_alter to hook into the Number field specifically.

 * Implements hook_field_widget_WIDGET_TYPE_form_alter().
function mymodule_field_widget_number_form_alter(&$element, &$form_state, $context) {
  $element['#type'] 'number';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.