-
Notifications
You must be signed in to change notification settings - Fork 1
/
form.py
120 lines (107 loc) · 3.29 KB
/
form.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
from flask_wtf import FlaskForm
from wtforms import (
BooleanField,
DateField,
DateTimeLocalField,
DecimalField,
DecimalRangeField,
EmailField,
FileField,
FloatField,
HiddenField,
IntegerField,
IntegerRangeField,
MonthField,
MultipleFileField,
PasswordField,
RadioField,
SearchField,
SelectField,
SelectMultipleField,
StringField,
SubmitField,
TelField,
TextAreaField,
TimeField,
URLField,
validators,
)
from wtforms.widgets import ColorInput, PasswordInput, WeekInput
class ColorField(StringField):
widget = ColorInput()
req = validators.InputRequired()
desc = "A description"
class KitchenSink(FlaskForm):
string = StringField("String", description=desc, validators=[req])
search = SearchField("Search", description=desc, validators=[req])
password = PasswordField(
"Password",
widget=PasswordInput(hide_value=False),
description=desc,
validators=[req],
)
email = EmailField("Email", description=desc, validators=[req, validators.Email()])
tel = TelField("Tel", description=desc, validators=[req])
url = URLField("URL", description=desc, validators=[req, validators.URL()])
textarea = TextAreaField("Text Area", description=desc, validators=[req])
boolean = BooleanField("Checkbox", description=desc, validators=[req])
choices = [("a", "A"), ("b", "B"), ("c", "C")]
radio = RadioField(
"Radio",
choices=choices,
description=desc,
validators=[validators.DataRequired()],
)
select = SelectField(
label="Select",
description=desc,
choices=[("", "-- Select --")] + choices,
validators=[req],
)
multiselect = SelectMultipleField(
label="Select Multiple", description=desc, choices=choices, validators=[req]
)
date = DateField("Date", description=desc, validators=[req])
datetimelocal = DateTimeLocalField(
"DateTime Local",
description=desc,
format="%Y-%m-%dT%H:%M",
validators=[req],
)
week = DateField(
"Week",
widget=WeekInput(),
description=desc,
validators=[req],
format="%Y-W%U",
)
month = MonthField("Month", description=desc, validators=[req])
time = TimeField("Time", description=desc, validators=[req])
integer = IntegerField("Integer", description=desc, validators=[req])
decimal = DecimalField("Decimal", description=desc, validators=[req])
float = FloatField("Float", description=desc, validators=[req])
integerrange = IntegerRangeField(
"Integer Range",
description=desc,
render_kw={"min": 0, "max": 100},
validators=[validators.NumberRange(min=51)],
)
decimalrange = DecimalRangeField(
"Decimal Range",
description=desc,
render_kw={"min": 0, "max": 100},
validators=[validators.NumberRange(min=51)],
)
file = FileField(
"File",
# validators=[FileRequired()],
description=desc,
)
multifile = MultipleFileField(
"Multi-File",
# validators=[FileRequired()],
description=desc,
)
color = ColorField("Color", description=desc)
hidden = HiddenField("", default="I'm hidden")
submit = SubmitField("Submit")