You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 12, 2024. It is now read-only.
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.
The text was updated successfully, but these errors were encountered:
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...
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.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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:
... 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.
The text was updated successfully, but these errors were encountered: