Reputation: 678
I have 3 inputs and a textarea in a Flask form
. When those are valid I change the CSS with the following code:
input:valid ~ label,
textarea:valid ~ label,
input:onfocus ~ label,
textarea:onfocus ~ label
{
/* Change style */
}
For the inputs there's no problem because they have the required
attribute. But the textarea is optional. So all the time is valid and the CSS is applied immediately. I would like to set a minlength
to the textare so it's only valid when length < 1
. I tried the following code in the wtform
but nothing happens.
{{ form.textareaName(minlength=1) }}
# I also tried with a String
{{ form.textareaName(minlength="1") }}
Some solution? Thanks!
Upvotes: 1
Views: 5358
Reputation: 2344
Use Length validator it validates the length of a string. You can set the minimum and maximum length required. i.e.
from wtforms.validators import Length
In your forms.py
,
textareaName = TextAreaField(validators=[Length(min=2)])
Upvotes: 4