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

Issue rendering submit button with 'btn btn-outline-primary' class #1299

Closed
4 tasks done
pedantic-curmudgeon opened this issue Aug 19, 2022 · 1 comment
Closed
4 tasks done

Comments

@pedantic-curmudgeon
Copy link

pedantic-curmudgeon commented Aug 19, 2022

  • Package version: 1.14.0
  • Django version: 4.0.5
  • Python version: 3.10.2
  • Template pack: bootstrap4

Description:

I am trying to style a Submit button with a css_class of btn btn-outline-primary from Boostrap4.

However, when I pass css_class='btn btn-outline-primary' into a Submit button, the rendered result is not as expected.

It appears that both the primary and primary outline classes are being rendered on top of each other.

This seems to be related to the following where the css_class is defaulted to btn btn-primary and the css_class passed into Submit is appended to it.

https://github.com/django-crispy-forms/django-crispy-forms/blob/1.14.0/crispy_forms/layout.py#L213
https://github.com/django-crispy-forms/django-crispy-forms/blob/1.14.0/crispy_forms/layout.py#L183-L184

Thanks!

Preferably also include:

  • Example Django Crispy Forms code
from crispy_forms.layout import Submit

Submit(
    'submit',
    'Save',
    css_class='btn btn-outline-primary',
)
  • Screenshots

Result
image

Expected
image

  • Actual HTML generated
<input type="submit" name="submit" value="Save" class="btn btn-primary btn btn-outline-primary" id="submit-id-submit">
  • Expected HTML
<input type="submit" name="submit" value="Save" class="btn btn-outline-primary" id="submit-id-submit">
@smithdc1
Copy link
Member

I think the current advice here would be to subclass the Submit button and add your custom field_classes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants