Ticket #3139: prefix-errors.diff
File prefix-errors.diff, 2.3 KB (added by , 18 years ago) |
---|
-
django/newforms/forms.py
173 173 def __init__(self, form, field, name): 174 174 self.form = form 175 175 self.field = field 176 self.name = form.add_prefix(name) 176 self.name = name 177 self.html_name = form.add_prefix(name) 177 178 self.label = self.field.label or pretty_name(name) 178 179 179 180 def __unicode__(self): … … 201 202 auto_id = self.auto_id 202 203 if auto_id and not attrs.has_key('id') and not widget.attrs.has_key('id'): 203 204 attrs['id'] = auto_id 204 return widget.render(self. name, self.data, attrs=attrs)205 return widget.render(self.html_name, self.data, attrs=attrs) 205 206 206 207 def as_text(self, attrs=None): 207 208 """ … … 223 224 "Returns the data for this BoundField, or None if it wasn't given." 224 225 if self.field.widget.requires_data_list and isinstance(self.form.data, MultiValueDict): 225 226 return self.form.data.getlist(self.name) 226 return self.form.data.get(self. name, None)227 return self.form.data.get(self.html_name, None) 227 228 data = property(_data) 228 229 229 230 def label_tag(self, contents=None): … … 251 252 """ 252 253 auto_id = self.form.auto_id 253 254 if auto_id and '%s' in str(auto_id): 254 return str(auto_id) % self. name255 return str(auto_id) % self.html_name 255 256 elif auto_id: 256 257 return self.name 257 258 return '' -
tests/regressiontests/forms/tests.py
1975 1975 >>> p.is_valid() 1976 1976 True 1977 1977 1978 Let's try submitting some bad data to make sure form.errors and field.errors 1979 work as expected. 1980 >>> data = { 1981 ... 'person1-first_name': u'', 1982 ... 'person1-last_name': u'', 1983 ... 'person1-birthday': u'' 1984 ... } 1985 >>> p = Person(data, prefix='person1') 1986 >>> len(p.errors) 1987 3 1988 >>> print p['first_name'].errors.as_ul() 1989 <ul class="errorlist"><li>This field is required.</li></ul> 1990 1978 1991 This is pretty unremarkable in and of itself, but let's create some data that 1979 1992 contains info for two different people. 1980 1993 >>> data = {