Skip to content
This repository was archived by the owner on Oct 12, 2024. It is now read-only.
This repository was archived by the owner on Oct 12, 2024. It is now read-only.

HTML5 field override? #24

@iandouglas

Description

@iandouglas

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions