-3

Drupal Core renders number input fields as the expected number HTML element type. Most browser render number fields with selector arrows.

Is there a way to render number fields as text fields so the selector arrows aren't shown?

New contributor
atomi is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
7
  • This is the ordinary behavior of the HTML number field type: developer.mozilla.org/en-US/docs/Web/HTML/Element/input/number. You could hack function preRenderNumber in core/lib/Drupal/Core/Render/Element/Number.php, write a module providing a custom field type, or possibly, use a template hook.
    – mona lisa
    Commented Dec 13 at 17:00
  • So Drupal 10 doesn't give you a simple option, e.g. via an add-on module, to let the website builder decide what kind of number field they want to solve when creating the field? Why isn't there a normal (old) number field? I don't want to hack the system for that.
    – atomi
    Commented Dec 13 at 17:11
  • I gave you three options, only one of which is hacking. Also, I don't know everything. drupal.org/node/1174640 (2012) added the markup to use the HTML5 standard number field type for number fields. Any question as to "why" would be found there.
    – mona lisa
    Commented Dec 13 at 17:27
  • You'd be better off hiding the arrows from the number field, leaving it as a number field, so that it can still be operated on as a number field, while appearing like a text field. An example would be when entering the value in a browser - if you use a textfield, the user is given the whole keyboard. If you make it a number field, the number pad is shown on mobile when filling in the field. w3schools.com/howto/howto_css_hide_arrow_number.asp
    – Jaypan
    Commented 2 days ago
  • Or, you're looking for a simple solution, maybe delete the number field and re-create it as a textfield.
    – Jaypan
    Commented 2 days ago

0

Your Answer

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

Browse other questions tagged or ask your own question.