Ticket #10573: focus_first.patch

File focus_first.patch, 1.1 KB (added by ales.zoulek@…, 16 years ago)

focusing first active form element

  • 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..2b7a120 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">
     59    (function(){
     60        var forms = document.forms || [];
     61        for(var i = 0; i < forms.length; i++){
     62            for(var j = 0; j < forms[i].length; j++){
     63                if(
     64                    forms[i][j].type != "hidden"
     65                    && forms[i][j].disabled != true
     66                    && forms[i][j].style.display != 'none'
     67                    && forms[i][j].nodeName.toLowerCase() != 'fieldset'
     68                ){
     69                    forms[i][j].focus();
     70                    return;
     71                }
     72            }
     73        }
     74    })();
     75</script>
    5976{% endif %}
    6077
    6178{# JavaScript for prepopulated fields #}
Back to Top