django-crispy-forms / django-crispy-forms/crispy-bootstrap5
Missing bootstrap tag: Card
- Dominant language
- HTML
- Stars
- 525
- Forks
- 77
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 2
Description
I before [issued this to django-crispy-forms](https://github.com/django-crispy-forms/django-crispy-forms/issues/1306) itself, while it is a crispy-bootstrap5 issue:
* Package version: crispy-bootstrap5==0.6, django-crispy-forms==1.14.0
* Django version: 4.1
* Python version:3.10
* Template pack: bootstrap5 - but should also work with bootsrtap4
### Description:
I am missing a Card template, modal and others exist.
I wrote my own, but I don't have time to make a PR ATM, maybe anyone else could?
The code is mostly borrowed from `modal.html` and the `Modal()` class
```python
class Card(LayoutObject):
"""
Layout object. It wraps fields in a Card.
Example:
Card(
'form_field_1',
'form_field_2',
title="Sample card"
subtitle="Always play nice."
)
"""
template = "%s/layout/card.html"
def __init__(
self,
*fields,
template=None,
css_id="modal_id",
title="Card Title",
title_id="card_title_id",
title_class="",
subtitle="",
css_class="",
**kwargs,
):
self.fields = list(fields)
self.template = template or self.template
self.css_id = css_id
self.css_class = css_class
self.title = title
self.title_id = title_id
self.title_class = title_class
self.subtitle = subtitle
kwargs = {
**kwargs,
"tabindex": "-1",
"role": "dialog",
"aria-labelledby": "%s-label" % self.title_id,
}
self.flat_attrs = flatatt(kwargs)
def render(self, form, form_style, context, template_pack=TEMPLATE_PACK, **kwargs):
fields = self.get_rendered_fields(
form, form_style, context, template_pack, **kwargs
)
template = self.get_template_name(template_pack)
return render_to_string(template, {"div": self, "fields": fields})
```
%s/layout/card.html:
```django
{{ div.title }}
{% if div.subtitle %} {{ div.subtitle }}{% endif %}
{{ fields|safe }}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.