Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

745
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda