Skip to content

Commit 030cee9

Browse files
paulchubatyydyve
authored andcommitted
Add ability to specify the form for radio input
Form inputs may be associated with different forms. It allows creating "forms within forms". Read a definition on [HTML spec](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fae-form). One can specify the form the input will be associated with like this: ```python sex = forms.ChoiceField( widget=forms.RadioSelect(attrs={"form": "order-create-form"}), choices=Order.SEX_CHOICES, label=_("Sex"), ) ```
1 parent b18845c commit 030cee9

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

src/django_bootstrap5/templates/django_bootstrap5/widgets/radio_select.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
id="{{ option.attrs.id }}"
1313
{% if option.value != None %} value="{{ option.value|stringformat:'s' }}"
1414
{% if option.attrs.checked %} checked="checked"{% endif %}{% endif %}
15+
{% if widget.attrs.form %} form="{{ widget.attrs.form }}{% endif %}
1516
{% if widget.attrs.disabled %} disabled{% endif %}>
1617
<label class="form-check-label" for="{{ option.attrs.id }}">{{ option.label }}</label>
1718
</div>

0 commit comments

Comments
 (0)