Fixed #17074 -- Improved first field detection in admin add form
Thanks Kidwind for the report and Julien Phalip for the initial patch.
This commit is contained in:
parent
92a710cd03
commit
1c0c879be3
|
@ -46,20 +46,6 @@ class AdminForm(object):
|
||||||
**options
|
**options
|
||||||
)
|
)
|
||||||
|
|
||||||
def first_field(self):
|
|
||||||
try:
|
|
||||||
fieldset_name, fieldset_options = self.fieldsets[0]
|
|
||||||
field_name = fieldset_options['fields'][0]
|
|
||||||
if not isinstance(field_name, six.string_types):
|
|
||||||
field_name = field_name[0]
|
|
||||||
return self.form[field_name]
|
|
||||||
except (KeyError, IndexError):
|
|
||||||
pass
|
|
||||||
try:
|
|
||||||
return next(iter(self.form))
|
|
||||||
except StopIteration:
|
|
||||||
return None
|
|
||||||
|
|
||||||
def _media(self):
|
def _media(self):
|
||||||
media = self.form.media
|
media = self.form.media
|
||||||
for fs in self:
|
for fs in self:
|
||||||
|
|
|
@ -66,8 +66,14 @@
|
||||||
|
|
||||||
{% block submit_buttons_bottom %}{% submit_row %}{% endblock %}
|
{% block submit_buttons_bottom %}{% submit_row %}{% endblock %}
|
||||||
|
|
||||||
{% if adminform.first_field and add %}
|
{% if adminform and add %}
|
||||||
<script type="text/javascript">document.getElementById("{{ adminform.first_field.id_for_label }}").focus();</script>
|
<script type="text/javascript">
|
||||||
|
(function($) {
|
||||||
|
$(document).ready(function() {
|
||||||
|
$('form#{{ opts.module_name }}_form :input:visible:enabled:first').focus()
|
||||||
|
});
|
||||||
|
})(django.jQuery);
|
||||||
|
</script>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{# JavaScript for prepopulated fields #}
|
{# JavaScript for prepopulated fields #}
|
||||||
|
|
Loading…
Reference in New Issue