meaning of `button_map` in the form_field definition in flask-bootstrap meaning of `button_map` in the form_field definition in flask-bootstrap flask flask

meaning of `button_map` in the form_field definition in flask-bootstrap


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.


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


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 mapeg

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