id,summary,reporter,owner,description,type,status,component,version,severity,resolution,keywords,cc,stage,has_patch,needs_docs,needs_tests,needs_better_patch,easy,ui_ux 18554,Template rendering based on value of hidden BooleanFields,David Seddon,nobody,"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 }} {{ form.bool1.value|yesno }}
}}} 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 %} }}}",Uncategorized,closed,Forms,1.3,Normal,worksforme,,,Unreviewed,0,0,0,0,0,0