0

EDIT 1

I've tryed using bith crispy-forms and widegt-tweaks but it doen't works.

Seems that widget=forms.RadioSelect() is not compatible with use of these 2 libraries together...


I want to display radio button inline using Boostrap.

I've tryed to add bootstrap form-check-inline class by setting attrs attribute of Django widget.

But When I debug, form-check-inline is not applyed. If I add form-check-inline class "manually" in div element containing radiobutton (see below) it works.

template.html

{{ form.eli_oui_ebo|as_crispy_field }} 

html page when inspected

<div class=""> ***<= here should be applyed form-check-inline class**** <div class="form-check"> <label for="id_id_eli_oui_ebo_0_1" class="form-check-label"> <input type="radio" class="form-check-input" name="eli_oui_ebo" id="id_id_eli_oui_ebo_0_1" value="0" class="test"> Non </label> </div> <div class="form-check"> <label for="id_id_eli_oui_ebo_0_2" class="form-check-label"> <input type="radio" class="form-check-input" name="eli_oui_ebo" id="id_id_eli_oui_ebo_0_2" value="1" class="test"> Oui </label> </div> </div> 

form.py

self.fields['eli_oui_ebo'] = forms.TypedChoiceField(label = 'A eu, dans les 72h, un contact avec un malade Ebola confirmé par RT-PCR',widget=forms.RadioSelect(attrs={'class': 'form-check-inline'},),required=False,choices=[i for i in Thesaurus.options_list(1,'fr') if i != (None,'')], empty_value=None, disabled=DISABLED)``` 

1 Answer 1

0

You can use wrapper_class "form-check-inline"

Please refer crispy-bootstrap5/django source: https://github.com/django-crispy-forms/crispy-bootstrap5/blob/main/crispy_bootstrap5/templates/bootstrap5/layout/inline_field.html

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.