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

Values not getting passed through when they're false in a boolean context #7

Closed
wants to merge 1 commit into from

Conversation

dmclain
Copy link
Contributor

@dmclain dmclain commented Mar 31, 2011

When the context is being populated in Input's get_context function the following code is run

if value:
    context['value'] = value

That prevents None from getting through (which is good), but it also prevents 0 getting through (this is bad). It also prevents False from going through (I am unsure as to whether that is good or bad). The use case that this messed up for me was a Select field defined as follows

Select(choices=([(hour % 12, hour) for hour in range(1,13)]))

Which when rendered with a value of 0 (regression testing via working just after midnight) resulted in no option being marked selected. When using django.forms.Select, I got the correct behavior.

@brutasse
Copy link
Collaborator

This is a bit tricky, I need to write a few tests to make sure no edge case is forgotten (or steal some from the django test suite). I'm doing {% if value %} checks in the templates and at this point if the value is 0 (int) it won't be displayed. If it's '0' (unicode) it will be... So I need to make sure the value is passed as a unicode string.

Thanks for the report, I'll probably release 0.5 when I'm confident this is fixed and tested :)

@brutasse
Copy link
Collaborator

brutasse commented Apr 2, 2011

Closed by 1e103dd - values are now passed as unicode strings

Thanks to Dave McLain for the report and initial patch.

The previous behaviour was passing values like 0 as raw values, thus
preventing them to be displayed with
{% if value %} value="{{ value }}"{% endif %}. The new behaviour is what
django does.

Also fixed a minor issue with the select widget that used to overwrite
self.choices instead of chaining it with the choices passed as an argument.

@brutasse brutasse closed this Apr 2, 2011
stefanfoulis pushed a commit to stefanfoulis/django-floppyforms that referenced this pull request Jul 22, 2011
Thanks to Dave McLain for the report and initial patch.

The previous behaviour was passing values like `0` as raw values, thus
preventing them to be displayed with
{% if value %} value="{{ value }}"{% endif %}. The new behaviour is what
django does.

Also fixed a minor issue with the select widget that used to overwrite
self.choices instead of chaining it with the choices passed as an argument.
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

Successfully merging this pull request may close these issues.

None yet

2 participants