Automatically set the field name as value for the HTML id attribute on the rendered widget.

This commit is contained in:
Lucian Mocanu 2014-05-04 00:12:08 +02:00
parent 5333a93126
commit 4e33ff05d9

View File

@ -154,7 +154,12 @@ class Field(object):
def widget_html(self): def widget_html(self):
if not self.widget: if not self.widget:
return '' return ''
return self.widget.render(self._name, self._value)
attrs = {}
if 'id' not in self.widget.attrs:
attrs['id'] = self._name
return self.widget.render(self._name, self._value, attrs=attrs)
def label_tag(self): def label_tag(self):
return '<label for="%s">%s:</label>' % (self._name, self.label) return '<label for="%s">%s:</label>' % (self._name, self.label)