Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WTForms: expose HTML5 fields #214

Closed
lafrech opened this issue Mar 2, 2016 · 7 comments
Closed

WTForms: expose HTML5 fields #214

lafrech opened this issue Mar 2, 2016 · 7 comments
Labels
type: enhancement Enhancement update for old feature
Milestone

Comments

@lafrech
Copy link
Member

lafrech commented Mar 2, 2016

WTForms added fields to support various HTML5 input types.

It would be nice to expose these.

Currently, I suppose on can subclass ModelConverter to override some converters.

We could add support in flask-mongoengine code. Maybe using a kwarg in the model definition.

@lafrech lafrech added the type: enhancement Enhancement update for old feature label Mar 2, 2016
@lafrech lafrech added this to the Scheduled, not planned milestone Mar 2, 2016
@lafrech
Copy link
Member Author

lafrech commented Mar 2, 2016

On second thought, it should not be in the model definition. Maybe in field_args.

I'm wondering:

  • Should this be specified for each field (can be painful), or could it be a form-wide parameter?
  • Should HTML5 widgets be default? Would this break anything? I'd rather go the conservative way and not make it default, which is acceptable if it can be a form-wide parameter.

@lafrech
Copy link
Member Author

lafrech commented Mar 3, 2016

Since old browsers fallback on text input if they don't handle new type input, it is probably safe to use HTML5 inputs wherever possible.

For instance

  • ME URLField -> WTF URLField -> WTF URLInput -> input type = "url"
  • ME DecimalField -> WTF DecimalField -> WTF NumberInput -> input type = "number"

In this case, I don't see the need for a parameter to specify whether or not to use them: what regression could it cause?

It should be quite straightforward to use a majority if not all of those fields already.

There might be corner cases a bit tricky to address, though. For instance, the regex that validates a URL might not be the same as the one specified in URLField.

@ripperdoc
Copy link

I made a local modification to use HTML5 from WTforms. Problem is for Datetime field. There are inconsistencies in browser support and seconds are not supported, while the underlying field does. So it is better to have it as a normal text-field or a custom date-picker.

http://stackoverflow.com/questions/21263515/why-is-html5-input-type-datetime-removed-from-browsers-already-supporting-it

@lafrech
Copy link
Member Author

lafrech commented Mar 6, 2016

Thanks for the feedback.

So you confirm that using HTML5 inputs by default won't harm (older browser will fallback to text input), so there's no need to make this optional, right?

In this case, I don't think anyone will object to adding this feature.

Do you have some code you would like to push here?

Let's add the easy ones already, and deal with the tricky ones like Datetime later on.

@ripperdoc
Copy link

Well, I haven't tested my code with many browsers, so cannot confirm no harm, but I give +1 for the idea.

@insspb
Copy link
Collaborator

insspb commented Jul 23, 2022

Since WTForms 3.0.0 HTML5 is default. This may raise only WTForms < 3.0.0 and Flask-Mongoengine compatibility issues... So I need to think about correct limits and make some tests before 2.0.0 release

@insspb
Copy link
Collaborator

insspb commented Jul 28, 2022

I checked compatibility, and according tests nothing broke in #497
So we are attached to WTForms >=3.0.0 since future 2.0.0 release, and will use/have HTML5 fields support.

@insspb insspb closed this as completed Jul 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Enhancement update for old feature
Projects
None yet
Development

No branches or pull requests

3 participants