2

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={})
nos
  • 19,875
  • 27
  • 98
  • 134

3 Answers3

3

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'}) }}
2

According to your link (see quick_form):

button_map – A dictionary, mapping button field names to names such as primary, danger or success. Buttons not found in the button_map will use the default 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.

dirn
  • 19,454
  • 5
  • 69
  • 74
1

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"} )}}