Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It seemed that render_kw in render_form is not working on the "class" property. #53

Closed
realJustinLee opened this issue Jan 7, 2020 · 3 comments
Labels
bug Something isn't working

Comments

@realJustinLee
Copy link

realJustinLee commented Jan 7, 2020

https://github.com/greyli/bootstrap-flask/blob/9ca1e7f0a2d3233d781f23da23ad919901a09183/flask_bootstrap/templates/bootstrap/form.html#L235

My code here:

class RegistrationForm(FlaskForm):
    submit = SubmitField('Register', render_kw={'class': 'btn-primary'})
{% from 'bootstrap/form.html' import render_form %}

{{ render_form(form) }}

The return is quite confusing:

<input class="btn btn-secondary" id="submit" name="submit" type="submit" value="Register">

And it seemed that render_form is not passing the render_kw of the SubmitField to the rendered html. This made me confused.

@realJustinLee realJustinLee changed the title It seemed that render_kw in render_form is not working. It seemed that render_kw in render_form is on the "class" property. Jan 7, 2020
@realJustinLee realJustinLee changed the title It seemed that render_kw in render_form is on the "class" property. It seemed that render_kw in render_form is not working on the "class" property. Jan 14, 2020
@greyli
Copy link
Member

greyli commented Mar 19, 2020

Since we need to add Bootstrap classes when calling this macro in the template, the old class defined with render_kw will be overwritten (it's WTForms's render behavior). You can config button style with button_map:

{{ render_form(form, button_map={'submit': 'primary'}) }}

It maps the field name to the Bootstrap button style, the value can be something like success, info, warning or outline-primary, outline-success, etc.

@realJustinLee
Copy link
Author

@greyli Is it possible to append the render_kw after the Bootstrap classes? I consider this would be a much better way to achieve a more developer friendly solution.

@greyli greyli added the bug Something isn't working label Apr 21, 2020
@greyli
Copy link
Member

greyli commented Apr 21, 2020

Just fix this in 708111a. Besides, this PR will bring a config called BOOTSTRAP_BTN_STYLE, you can use it to set a global button default style.

@greyli greyli closed this as completed Apr 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants