Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

746
Views
WTForms equivalent to <input type="datetime-local">

I would like to know if it's possible to create a dropdown datetime field for the DateTimeField in WTForms, the way renders in HTML.
A dropdown menu is much more user friendly than the default in WTForms where a user has to type in the date and time in the exact correct format.
And if it's not possible using only WTForms then how would I be able to implement the raw HTML into a WTForm as I would still like to use the security CSRF token that is provided by WTForms.
Thanks in advance!
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

The html5 fields provided by WTForms do include a DateTimeLocalField - v2.3.x, v3.0.x. Thus (v2.3)

from wtforms.fields.html5 import DateTimeLocalField
dttm = DateTimeLocalField("Date/Time: ", format="%Y-%m-%dT%H:%M")

will show the html5 date picker and time picker popups on browsers that support them (support is varied).

I find you need to specify format="%Y-%m-%dT%H:%M" - note the T - because the default format="%Y-%m-%d %H:%M" fails validation (see quote below).

input type="datetime" appears to be deprecated, so browsers fall back to plain text entry: input type="datetime" | MDN. input type="datetime-local", and thus WTForms DateTimeLocalField, should always be used: input type="datetime-local" | MDN.

From the latter:

One thing to note is that the displayed date and time formats differ from the actual value; the displayed date and time are formatted according to the user's locale as reported by their operating system, whereas the date/time value is always formatted YYYY-MM-DDThh:mm.

over 4 years ago · Santiago Trujillo Report

0

Ok after being forced to read the WTForms documentation because nobody immediately answered my question I now understand that it can be manipulated to do anything HTML can do by passing in HTML keyword arguments like so:

{{ form.when.label }}<br>
{{ form.when(type='datetime-local') }}

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!