I am reading the documentation of flask-boostrap doc. In the form_field
definition, what is the purpose of the button_map
?
form_field(field, form_type="basic", horizontal_columns=('lg', 2, 10), button_map={})
I am reading the documentation of flask-boostrap doc. In the form_field
definition, what is the purpose of the button_map
?
form_field(field, form_type="basic", horizontal_columns=('lg', 2, 10), button_map={})
If you render form as a quick_form then 'btn-primary' class will be added to 'submit' button.
{{ wtf.quick_form(form, button_map={'submit': 'primary'}) }}
According to your link (see quick_form
):
button_map – A dictionary, mapping button field names to names such as
primary
,danger
orsuccess
. Buttons not found in thebutton_map
will use thedefault
type of button.
That means if you did something like
form_field(submit_button, button_map={'submit_button': 'primary'})
you'd get a button with primary
as its type.
As the docs also mention, form_field
is used primarily by quick_form
where a mapping makes more sense than for an individual field.
In the above two answers, whatever name you use to call your SubmitField (ie. submit button) when you create your Flask form, is the same name you use inside the map eg
##WTForm
class CreatePostForm(FlaskForm):
#some code here
submit_button = SubmitField("Submit Post")
Your quick form will be:
{{wtf.quick_form(form, novalidate=True, button_map = {"submit_button":"primary"} )}}