Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

747
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda