Ticket #11632: show_hidden_initial.diff

File show_hidden_initial.diff, 1.7 KB (added by Mark Lavin, 15 years ago)
  • django/forms/forms.py

     
    343343        self.name = name
    344344        self.html_name = form.add_prefix(name)
    345345        self.html_initial_name = form.add_initial_prefix(name)
     346        self.html_initial_id = form.add_initial_prefix(self.auto_id)
    346347        if self.field.label is None:
    347348            self.label = pretty_name(name)
    348349        else:
     
    374375        attrs = attrs or {}
    375376        auto_id = self.auto_id
    376377        if auto_id and 'id' not in attrs and 'id' not in widget.attrs:
    377             attrs['id'] = auto_id
     378            if not only_initial:
     379                attrs['id'] = auto_id
     380            else:
     381                attrs['id'] = self.html_initial_id
    378382        if not self.form.is_bound:
    379383            data = self.form.initial.get(self.name, self.field.initial)
    380384            if callable(data):
  • tests/regressiontests/forms/forms.py

     
    18071807>>> [f.name for f in form.visible_fields()]
    18081808['artist', 'name']
    18091809
     1810# Hidden initial input gets its own unique id ################################
     1811
     1812>>> class MyForm(Form):
     1813...     field1 = CharField(max_length=50, show_hidden_initial=True)
     1814>>> print MyForm()
     1815<tr><th><label for="id_field1">Field1:</label></th><td><input id="id_field1" type="text" name="field1" maxlength="50" /><input type="hidden" name="initial-field1" id="initial-id_field1" /></td></tr>
     1816
    18101817"""
Back to Top