mirror of
https://github.com/ngfchl/ptools
synced 2023-07-10 13:41:22 +08:00
1. 重新初始化
This commit is contained in:
33
static/admin/js/change_form.js
Normal file
33
static/admin/js/change_form.js
Normal file
@@ -0,0 +1,33 @@
|
||||
/*global gettext*/
|
||||
'use strict';
|
||||
{
|
||||
const inputTags = ['BUTTON', 'INPUT', 'SELECT', 'TEXTAREA'];
|
||||
const modelName = document.getElementById('django-admin-form-add-constants').dataset.modelName;
|
||||
let submitted = false;
|
||||
|
||||
if (modelName) {
|
||||
const form = document.getElementById(modelName + '_form');
|
||||
|
||||
form.addEventListener('submit', (event) => {
|
||||
event.preventDefault();
|
||||
if (submitted) {
|
||||
const answer = window.confirm(gettext('You have already submitted this form. Are you sure you want to submit it again?'));
|
||||
if (!answer) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
;
|
||||
event.target.submit();
|
||||
submitted = true;
|
||||
});
|
||||
|
||||
for (const element of form.elements) {
|
||||
// HTMLElement.offsetParent returns null when the element is not
|
||||
// rendered.
|
||||
if (inputTags.includes(element.tagName) && !element.disabled && element.offsetParent) {
|
||||
element.focus();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user