Ticket #10573: admin.diff

File admin.diff, 1.5 KB (added by rduffield, 6 years ago)
  • django/forms/forms.py

     
    1010from django.utils.safestring import mark_safe
    1111
    1212from fields import Field, FileField
    13 from widgets import Media, media_property, TextInput, Textarea
     13from widgets import Media, media_property, TextInput, Textarea, MultiWidget
    1414from util import flatatt, ErrorDict, ErrorList, ValidationError
    1515
    1616__all__ = ('BaseForm', 'Form')
     
    434434            return self.html_name
    435435        return ''
    436436    auto_id = property(_auto_id)
     437
     438    def _focus_id(self):
     439        """
     440        Returns the correct field to auto-focus on when rendering the form.
     441        """
     442        if isinstance(self.field.widget, MultiWidget):
     443            return '%s_0' % self.auto_id
     444        else:
     445            return self.auto_id
     446    focus_id = property(_focus_id)
  • django/contrib/admin/templates/admin/change_form.html

     
    5555{% submit_row %}
    5656
    5757{% if add %}
    58    <script type="text/javascript">document.getElementById("{{ adminform.first_field.auto_id }}").focus();</script>
     58   <script type="text/javascript">document.getElementById("{{ adminform.first_field.focus_id }}").focus();</script>
    5959{% endif %}
    6060
    6161{# JavaScript for prepopulated fields #}
Back to Top