#5136 closed (wontfix)
Give BoundField an is_required property
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | Forms | Version: | dev |
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 |
Description
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/"> <table> <tr><th>OpenID:</th><td>{{userprof.openid}}</td></tr> {% for field in modify_form %} <tr> <th>{{field.label_tag}}{% if field.required %}<span class="required">*</span>{% endif %}:</th> <td> {% if field.errors %}{{field.errors}}{% endif %} {{field}} {% if field.help_text %}<br/><span class="help">{{field.help_text}}</span>{% endif %} </td> </tr> {% endfor %} </table> <p><input type="submit" value="수정하기" /></p> </form>
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 by , 17 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:3 by , 17 years ago
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/forms.old.py
+++ /usr/lib/python2.4/site-packages/django/newforms/forms.py
@@ -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 by , 17 years ago
Resolution: | invalid |
---|---|
Status: | closed → reopened |
comment:5 by , 17 years ago
Summary: | newforms field required attribute is not evaluated in templates → Give BoundField an is_required property |
---|---|
Triage Stage: | Unreviewed → Design 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 by , 17 years ago
Resolution: | → wontfix |
---|---|
Status: | reopened → closed |
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.
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.