Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting data attributes on a WTForms field

I want to add "data-" attributes to a form field for integration with Bootstrap. I tried the following in a template:

{{ form.test(data-toggle="toggle", data-size="mini", data-on="Yes", data-off="No", type="checkbox")}}

and got this error:

TemplateSyntaxError: expected token ',', got '='

Why did I get this error and how do I fix it?

like image 846
user977828 Avatar asked Jan 05 '15 11:01

user977828


People also ask

What does WTForms stand for?

WTF stands for WT Forms which is intended to provide the interactive user interface for the user. The WTF is a built-in module of the flask which provides an alternative way of designing forms in the flask web applications.

What is FlaskForm?

The FlaskForm base class is defined by the Flask-WTF extension, so it is imported from flask_wtf . The fields and validators, however, are imported directly from the WTForms package. The list of standard HTML fields supported by WTForms is shown in Table 4-1. Table 4-1. WTForms standard HTML fields.

What is StringField?

StringField (default field arguments)[source] This field is the base for most of the more complicated fields, and represents an <input type="text"> .


1 Answers

If you want to add an attribute like "disabled" or "readonly" then you can do it like this

{{ form.test(class_="input", readonly="readonly") }}
like image 147
FineJ Avatar answered Oct 14 '22 16:10

FineJ