Repository navigation
Fix render_field losing boolean type for attributes like checked - #170
Open
juneja-varun wants to merge 1 commit into
Open
juneja-varun wants to merge 1 commit into
juneja-varun wants to merge 1 commit into
Conversation
juneja-varun
force-pushed
the
fix-render-field-boolean-attrs
branch
from
September 7, 2026 20:03
c4c64bf to
1ae671c
Compare
Author
|
Just checking in on this one — happy to address any feedback. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #104.
I had a checkbox rendered with
{% render_field form.is_completed checked=some_bool %}, and whensome_boolwasFalseit still renderedchecked="False"- which every browser treats as checked, since HTML has no falsy value for a boolean attribute, only presence/absence.Root cause:
render_fieldresolves the attribute value from the template, then hands it toset_attr/append_attrby building a string likef"checked:{value}"- which stringifies the value before it gets split back apart. So a real PythonFalsebecomes the literal text"False", and Django's own widget rendering (which checksvalue is not False/value is not Trueto decide whether to omit the attribute or render it bare) never sees the actual boolean.Fixed by having
render_fieldhand the resolved value straight through, without the round trip through a string. Kept the attribute name's existing::escaping (documented in the README for names with a literal colon, likev-bind::class) working the same as before - caught a regression in my first draft here via the existingtest_alpinejs_event_modifiertest, which exercises exactly that. Added a test for the checked=True/False case on both directions.