Skip to content

Fix #7722. - #7882

Closed
tbrknt wants to merge 2 commits into
encode:masterfrom
tbrknt:fix-null-boolean-rendering-7722
Closed

tbrknt wants to merge 2 commits into
encode:masterfrom
tbrknt:fix-null-boolean-rendering-7722

Conversation

@tbrknt

@tbrknt tbrknt commented Mar 29, 2021

Copy link
Copy Markdown
Contributor

Render BooleanFields with allow_null=True as HTML select rather than as
HTML checkbox in Browsable API #7722.

Description

This PR is created in order to fix issue #7722. A serializer field of type BooleanField with allow_null=True was being rendered as HTML checkbox elements on Browsable API forms even though three values (True, False, and None/null) are possible. It was also happening for the model BooleanField instances with allow_null=True that are converted to serializer BooleanField instances. In this PR, I worked on keeping the checkbox rendering for BooleanFields with allow_null=False while providing dropdown rendering (HTML select element) for BooleanFields with allow_null=True.

fix #7722
refs #7722

@lovelydinosaur

Copy link
Copy Markdown
Member

Thanks for working on this. Having a look over, I'm wondering about the alternative of not introducing a new template, and using the existing "select.html" template.

Render BooleanFields with allow_null=True as HTML select rather than as
HTML checkbox in Browsable API encode#7722.
@tbrknt
tbrknt force-pushed the fix-null-boolean-rendering-7722 branch from 5e2b339 to 5c9bd01 Compare March 29, 2021 14:38
@tbrknt

tbrknt commented Mar 29, 2021

Copy link
Copy Markdown
Contributor Author

Hi @tomchristie ,
Thank you for your comment. I was thinking about that alternative too. The following part from select.html was my main hesitation to use it. I was not sure if I should adapt the value of BooleanField and that part of the template. Without changing that template, I could not think of a solution to drop -------- and introduce unknown option. What do you think about it?
If unknown option is not that important, I believe it is possible to make the value of the BoundField as 'False' string instead of False boolean value. That way, for False, we can avoid if not field.value.

  <select class="form-control" name="{{ field.name }}">
    {% if field.allow_null or field.allow_blank %}
      <option value="" {% if not field.value %}selected{% endif %}>--------</option>
    {% endif %}
  </select>

@stale

stale Bot commented Apr 29, 2022

Copy link
Copy Markdown

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale Bot added the stale label Apr 29, 2022

@auvipy auvipy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please rebase and make it merge able again, please

@stale stale Bot removed stale labels Nov 22, 2022
@stale

stale Bot commented Jan 21, 2023

Copy link
Copy Markdown

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale Bot added the stale label Jan 21, 2023
@auvipy auvipy removed the stale label Jan 21, 2023
@merwok

merwok commented Jan 21, 2023

Copy link
Copy Markdown
Contributor

Could the PR title have some words in it to describe the bug or the fix? Would help all of us looking at notifications or lists of tickets. Thanks!

@stale

stale Bot commented Mar 25, 2023

Copy link
Copy Markdown

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale Bot added stale and removed stale labels Mar 25, 2023
@stale

stale Bot commented Jun 11, 2023

Copy link
Copy Markdown

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale Bot added stale and removed stale labels Jun 11, 2023
@stale

stale Bot commented Aug 12, 2023

Copy link
Copy Markdown

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale Bot added stale and removed stale labels Aug 12, 2023
@auvipy

auvipy commented Aug 13, 2023

Copy link
Copy Markdown
Collaborator

we might need a new taker for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants