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

forms.RadioSelect stacks choices vertically instead of horizontally #1034

Closed
kenricci opened this issue Oct 18, 2023 · 5 comments
Closed

forms.RadioSelect stacks choices vertically instead of horizontally #1034

kenricci opened this issue Oct 18, 2023 · 5 comments
Assignees

Comments

@kenricci
Copy link

admin.py

class OTReqQuestionAdminForm(forms.ModelForm):
    class Meta:
        model = OTReqQuestion
        fields = '__all__'

    def __init__(self, *args, **kwargs):
        super(OTReqQuestionAdminForm, self).__init__(*args, **kwargs)
        self.fields['answer'].widget = forms.RadioSelect(choices=((1, 'Yes'), (0, 'No'), (3, 'N/A'),))

Grappelli 3.0.8 with Django 4.0.10 stacks choices vertically as shown here
vertical_stack

Grappelli 2.13.3 with Django 2.2.10 stacks horizontally as shown here
horizontal_stack

@sehmaschine
Copy link
Owner

you are aware that you already opened a ticket? see #1021 ... fixed with stable/3.0.x

@kenricci
Copy link
Author

kenricci commented Oct 18, 2023 via email

@kenricci
Copy link
Author

working html

<div class="grp-td answer">
  <ul id="id_otreqquestion_set-0-answer">
    <li>
      <label for="id_otreqquestion_set-0-answer_0"
        ><input
          type="radio"
          name="otreqquestion_set-0-answer"
          value="1"
          id="id_otreqquestion_set-0-answer_0"
        />
        Yes</label
      >
    </li>
    <li>
      <label for="id_otreqquestion_set-0-answer_1"
        ><input
          type="radio"
          name="otreqquestion_set-0-answer"
          value="0"
          id="id_otreqquestion_set-0-answer_1"
        />
        No</label
      >
    </li>
    <li>
      <label for="id_otreqquestion_set-0-answer_2"
        ><input
          type="radio"
          name="otreqquestion_set-0-answer"
          value="3"
          id="id_otreqquestion_set-0-answer_2"
          checked=""
        />
        N/A</label
      >
    </li>
  </ul>
</div>

Broken html

<div class="grp-td answer">
  <div id="id_otreqquestion_set-0-answer">
    <div>
      <label for="id_otreqquestion_set-0-answer_0"
        ><input
          type="radio"
          name="otreqquestion_set-0-answer"
          value="1"
          id="id_otreqquestion_set-0-answer_0"
        />
        Yes</label
      >
    </div>
    <div>
      <label for="id_otreqquestion_set-0-answer_1"
        ><input
          type="radio"
          name="otreqquestion_set-0-answer"
          value="0"
          id="id_otreqquestion_set-0-answer_1"
        />
        No</label
      >
    </div>
    <div>
      <label for="id_otreqquestion_set-0-answer_2"
        ><input
          type="radio"
          name="otreqquestion_set-0-answer"
          value="3"
          id="id_otreqquestion_set-0-answer_2"
          checked=""
        />
        N/A</label
      >
    </div>
  </div>
</div>

@kenricci
Copy link
Author

Appears to be in TabularInline forms

@parsch parsch self-assigned this Oct 19, 2023
@parsch
Copy link
Collaborator

parsch commented Oct 23, 2023

The new html that only uses div cannot be layouted differently by default because it does not have a specific attribute. If you define the CSS class "radiolist inline" for the widget, the list will also appear as such (but you will almost certainly have to define a width for the list as well).

radiolist_tabularinline

@parsch parsch closed this as completed Oct 23, 2023
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

3 participants