-
-
Notifications
You must be signed in to change notification settings - Fork 16
HTML5 field override? #24
Description
Love the library, thanks for taking the time to build it!
I'm trying to figure out whether/how I could override default field types to enable HTML5 fields. For example, Email and PhoneNumber both default to calling get_TextField()
As a test, I did
from wtform.fields import html5 as h5f
And override the functions like this:
def convert_EmailProperty(model, prop, kwargs):
"""Returns a form field for a db.EmailProperty."""
kwargs['validators'].append(validators.email())
return h5f.EmailField(**kwargs)
... and now my db.EmailProperty() field types show up as <input ... type="email" ... and db.PhoneNumberProperty() fields show up as <input ... type="tel" ...
But I'm wondering whether it'd be worth having a parameter passed in model_form() or as a field_arg to override the default type with a specific HTML5 input field type and do a logic check in these functions to look for that override switch, perhaps?
I'd be happy to get a pull request in if you think it's worthwhile.