Wednesday, March 30, 2016

Why doesn't {{ form.field.value }} return cleaned data?

Say I have a TypedMultipleChoiceField and I'm building a custom select multiple widget in my template.

If I want to check a box based on an initial value (ie. default checked options), OR check a box based on form data that has been returned (ie. error state), I would do this:

<input type="checkbox" {% if form.field.value %}checked{% endif %}>

HOWEVER, {{form.field.value}} source documentation ( states: "Returns the value for this BoundField, using the initial value if the form is not bound or the data otherwise."

So basically the equivalent of:
return ( or form.field.initial)

Wouldn't it be more appropriate and useful for boundfield.value to return CLEANED data that has gone through to_python()? As in:
return (form.field.cleaned_data or form.field.initial)

You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
To view this discussion on the web visit
For more options, visit

No comments:

Post a Comment