Ticket #14858: change_form_r14851_js_bug_fix.diff

File change_form_r14851_js_bug_fix.diff, 1.1 KB (added by mkelley33 <michauxkelley@…>, 13 years ago)

Patch for JavaScript bug in change_form.html on admin site.

  • django/contrib/admin/templates/admin/change_form.html

     
    6060{% submit_row %}
    6161
    6262{% if adminform and add %}
    63    <script type="text/javascript">document.getElementById("{{ adminform.first_field.auto_id }}").focus();</script>
     63<script type="text/javascript">
     64    var adminform = document.forms["{{ opts.module_name }}_form"];
     65    var first_field = adminform["{{ adminform.first_field.auto_id }}"];
     66    if(first_field !== undefined) {
     67        first_field.focus();
     68    } else {
     69        // First field could be datetime split into two fields.
     70        // For example: id_created_datetime_0
     71        first_field = adminform["{{ adminform.first_field.auto_id }}_0"];
     72        first_field.focus()
     73        // In the very exceptional circumstance that the
     74        // first_field is still undefined let it error.
     75    }
     76</script>
    6477{% endif %}
    6578
    6679{# JavaScript for prepopulated fields #}
Back to Top