unarm massinput-buttons earlier
This commit is contained in:
parent
7f9071ec96
commit
2f8588da96
@ -46,6 +46,13 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
massInputFormSubmitHandler = makeSubmitHandler();
|
massInputFormSubmitHandler = makeSubmitHandler();
|
||||||
|
|
||||||
|
// "unarm" submit buttons inside this massinput so browser
|
||||||
|
// uses correct submit button for form submission.
|
||||||
|
// contents of the massinput will be replaced either way,
|
||||||
|
// so unarming is no problem
|
||||||
|
unarmSubmitButtons(massInputFormSubmitHandler);
|
||||||
|
|
||||||
massInputForm.addEventListener('submit', massInputFormSubmitHandler);
|
massInputForm.addEventListener('submit', massInputFormSubmitHandler);
|
||||||
|
|
||||||
// mark initialized
|
// mark initialized
|
||||||
@ -75,12 +82,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
return function(event) {
|
return function(event) {
|
||||||
// "unarm" submit buttons inside this massinput so browser
|
|
||||||
// uses correct submit button for form submission.
|
|
||||||
// contents of the massinput will be replaced either way,
|
|
||||||
// so unarming is no problem
|
|
||||||
unarmSubmitButtons();
|
|
||||||
|
|
||||||
// check if event occured from either a mass input add/delete button or
|
// check if event occured from either a mass input add/delete button or
|
||||||
// from inside one of massinput's inputs (i.e. they are focused/active)
|
// from inside one of massinput's inputs (i.e. they are focused/active)
|
||||||
var activeElement = element.querySelector(':focus, :active');
|
var activeElement = element.querySelector(':focus, :active');
|
||||||
@ -129,11 +130,13 @@
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function unarmSubmitButtons() {
|
function unarmSubmitButtons(submitHandler) {
|
||||||
var buttons = Array.from(element.querySelectorAll('button[type="submit"][name][value]'));
|
var buttons = Array.from(element.querySelectorAll('button[type="submit"][name][value]'));
|
||||||
buttons.forEach(function(button) {
|
buttons.forEach(function(button) {
|
||||||
button.setAttribute('type', 'button');
|
button.setAttribute('type', 'button');
|
||||||
button.classList.add(MASS_INPUT_SUBMIT_BUTTON_CLASS);
|
button.classList.add(MASS_INPUT_SUBMIT_BUTTON_CLASS);
|
||||||
|
|
||||||
|
button.addEventListener('click', submitHandler);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,6 +195,12 @@
|
|||||||
function reset() {
|
function reset() {
|
||||||
element.classList.remove(MASS_INPUT_INITIALIZED_CLASS);
|
element.classList.remove(MASS_INPUT_INITIALIZED_CLASS);
|
||||||
massInputForm.removeEventListener('submit', massInputFormSubmitHandler)
|
massInputForm.removeEventListener('submit', massInputFormSubmitHandler)
|
||||||
|
|
||||||
|
Array.from(element.querySelectorAll('.' + MASS_INPUT_SUBMIT_BUTTON_CLASS)).forEach(function(button) {
|
||||||
|
button.removeEventListener('click', submitHandler);
|
||||||
|
button.classList.remove(MASS_INPUT_SUBMIT_BUTTON_CLASS);
|
||||||
|
button.setAttribute('type', 'submit');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return init();
|
return init();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user