Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#5136 closed (wontfix)

Give BoundField an is_required property

Reported by: daybreaker12@… Owned by: Adrian Holovaty
Component: Forms Version: master
Severity: Keywords: field required template evaluation
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I'm using newforms form object as following:

from django import newforms as forms

class ModifyForm(forms.Form):
    email = forms.EmailField(required=True, label=u'E-Mail')
    homepage = forms.URLField(required=False, label=u'홈페이지')
    signature = forms.CharField(widget=forms.Textarea, required=False, label=u'서명', help_text=u'자신이 올린 자료나 글의 끝에 따라붙는 텍스트입니다.')
            <form id="form-ModifyUser" method="post" action="/user/modify/">
                {% for field in modify_form %}
                    <th>{{field.label_tag}}{% if field.required %}<span class="required">*</span>{% endif %}:</th>
                        {% if field.errors %}{{field.errors}}{% endif %}
                        {% if field.help_text %}<br/><span class="help">{{field.help_text}}</span>{% endif %}
                {% endfor %}
            <p><input type="submit" value="수정하기" /></p>

But field.required returns always None, not True or False, so I cannot display a required asterisk mark for required fields.
Other options such as help_text works fine.

Change History (7)

comment:1 Changed 11 years ago by Malcolm Tredinnick

Resolution: invalid
Status: newclosed

The "field" in your template is a newforms.forms.BoundField instance. So you want field.field.required.

In future, please ask support questions on the django-users mailing list. This Trac is for bug reports only.

comment:2 Changed 11 years ago by daybreaker12@…

Thanks, I didn't know that this is actually a bug.

comment:3 Changed 11 years ago by Knox Harrington

This doesn't seem very intuitive, would it not be preferable to be able to acess field.required in a template ?

Not realizing that you could access this with field.field.required, I wrote a patch to access thin in a template :

--- /usr/lib/python2.4/site-packages/django/newforms/
+++ /usr/lib/python2.4/site-packages/django/newforms/
@@ -307,6 +307,11 @@

"Returns True if this BoundField's widget is hidden."
return self.field.widget.is_hidden

is_hidden = property(_is_hidden)

+ def _is_required(self):
+ "Returns True if this Field is required."
+ return self.field.required
+ is_required = property(_is_required)

def _auto_id(self):


comment:4 Changed 11 years ago by anonymous

Resolution: invalid
Status: closedreopened

comment:5 Changed 11 years ago by Chris Beaven

Summary: newforms field required attribute is not evaluated in templatesGive BoundField an is_required property
Triage Stage: UnreviewedDesign decision needed

Agreed Knox, it isn't very intuitive (and has come up before in several previous discussions). I'll promote to design decision - care to attach your patch as a file?

comment:6 Changed 11 years ago by Malcolm Tredinnick

Resolution: wontfix
Status: reopenedclosed

You can already access it one way. That is enough. A documentation patch to indicate that the underlying field object is available via field.field will be accepted (so as not to just special case this instance) if it's opened as an appropriate ticket.

comment:7 Changed 11 years ago by knox <christobzr@…>

Ticket #5854 now has a proposed patch for this.

Note: See TracTickets for help on using tickets.
Back to Top