HTML5 field override?
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.
Sorry for the delay. I'm fine with moving to html5 forms where backwards-compatible, though I'm a bit confused with what you're proposing...
The above override of convert_EmailProperty already works, right? And the use of html5 forms (at least for ones we'd use like email and phone number) are entirely backwards-compatible, right? I'd be open to a change like that.
But I was confused: since the model_form is used for the model as a whole (and not any individual field), it so seems like the wrong place for field-specific overrides. Or are you proposing an html5=True argument to model_form()? Sorry, I think I'm not understanding the justification/implementation of your proposal...
Sorry for the confusion and late response.
Yes, I was asking about an html5-True parameter to model_form() for fields which could potentially be turned into proper HTML5 input types for things like Email addresses and phone numbers, etc..
Ahh, then if that's the case, then I think we don't actually need an html5=True parameter. Since these HTML5 properties are backwards-compatible, I'd be open to just using the html5 properties all the time.