Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask WTForms Integerfield type is text instead of number

This is what I have tried:

nrkomp = IntegerField('Number',validators=[NumberRange(min=1, max=5, message='Invalid length')])

In developer tools, this form input has type text and not number, I have read the docs, but could not find a solution to this problem.

like image 616
KobraCode Avatar asked Nov 23 '18 16:11

KobraCode


1 Answers

You can use wtforms html5 fields to get html5 input types, and html5 widgets as their associated widgets.

from wtforms import Form
from wtforms.fields import html5 as h5fields
from wtforms.widgets import html5 as h5widgets


class F(Form):

    n1 = h5fields.IntegerField("Number1")
    n2 = h5fields.IntegerField(
        "Number2", widget=h5widgets.NumberInput(min=0, max=100, step=10)
    )


for f in F():
    print(f)
<input id="n1" name="n1" step="1" type="number" value="">
<input id="n2" max="100" min="0" name="n2" step="10" type="number" value="">
like image 147
snakecharmerb Avatar answered Oct 15 '22 01:10

snakecharmerb