#18554: Template rendering based on value of hidden BooleanFields
-------------------------------+--------------------
Reporter: seddonym | Owner: nobody
Type: Uncategorized | Status: new
Component: Forms | Version: 1.3
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
I'm not sure if this is a bug or not, but it's caused me quite a headache
so I thought I'd report it.
It comes down to wanting to make decisions in the template based on the
value of a Boolean HiddenInput field. Essentially you have to use strings
instead of Boolean values to get it working, which doesn't seem right.
Here's the code:
The form:
{{{
class TestForm(forms.Form):
text1 = forms.CharField()
text2 = forms.CharField()
bool1 = forms.BooleanField(required=False, widget=forms.HiddenInput)
}}}
The view:
{{{
def testview(request):
if request.method == 'POST':
form = TestForm(request.POST)
else:
form = TestForm(initial={'bool1':True})
return render_to_response('test_form.html', {'form': form})
}}}
The template:
{{{
<form method='post' action=''>
{{ form }}
{{ form.bool1.value|yesno }}
<button>Submit</button>
</form>
}}}
What I would expect to happen is to be able to use the yesno filter (or at
the very least the 'if' tag) to test if the value in the boolean field is
True or False. This doesn't work though, if the other fields fail to
validate and the form is resubmitted.
In the end I had to make the following changes. I can understand the
first (since maybe initial should just be all strings?) but the ifequal
method in the template seems clumsy:
{{{
#Pass the initial value as a string
form = TestForm(initial={'bool1':'True'})
}}}
{{{
{% ifequal form.bool1.value 'True' %}yes{% else %}no{% endifequal %}
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/18554>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.