Ticket #10573: focus_first.2.patch

File focus_first.2.patch, 1.3 KB (added by ales_zoulek, 6 years ago)
  • django/contrib/admin/templates/admin/change_form.html

    diff --git a/django/contrib/admin/templates/admin/change_form.html b/django/contrib/admin/templates/admin/change_form.html
    index 2fb17bb..c493329 100644
    a b  
    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">
     59try {
     60    document.getElementById("{{ adminform.first_field.auto_id }}").focus()
     61} catch(TypeError) {
     62    (function(){
     63        var forms = document.forms || [];
     64        for(var i = 0; i < forms.length; i++){
     65            for(var j = 0; j < forms[i].length; j++){
     66                if(
     67                    forms[i][j].type != "hidden"
     68                    && forms[i][j].disabled != true
     69                    && forms[i][j].style.display != 'none'
     70                    && forms[i][j].style.visibility != 'hidden'
     71                    && forms[i][j].nodeName.toLowerCase() != 'fieldset'
     72                ){
     73                    forms[i][j].focus();
     74                    return;
     75                }
     76            }
     77        }
     78    })();
     79}
     80</script>
    5981{% endif %}
    6082
    6183{# JavaScript for prepopulated fields #}
Back to Top