pythonflaskwtformsflask-wtforms

How do I use "tel", "number", or other input types in WTForms?


I want to use a phone number field in my form. What I need is when this field is tapped on Android phone, not general keyboard, but digital only appears.

I learned that this can be achieved by using <input type="tel" or <input type="number".

How do I use the tel or number input types in WTForms?


Solution

  • In WTForms >= 3.0, they are defined along with other common fields, and can be imported from wtforms.fields.

    from wtforms.fields import TelField
    
    phone_number = TelField()
    

    Previously, they were available from wtforms.fields.html5. They were missing from the docs until version 2.3.

    from wtforms.fields.html5 import TelField