add keyboard support for mass inputs
This commit is contained in:
parent
351f7ace74
commit
ea697d16cb
@ -49,14 +49,13 @@
|
|||||||
|
|
||||||
// setup submit buttons inside this massinput so browser
|
// setup submit buttons inside this massinput so browser
|
||||||
// uses correct submit button for form submission.
|
// uses correct submit button for form submission.
|
||||||
// contents of the massinput will be replaced either way,
|
|
||||||
// so unarming is no problem
|
|
||||||
var buttons = getMassInputSubmitButtons();
|
var buttons = getMassInputSubmitButtons();
|
||||||
buttons.forEach(function(button) {
|
buttons.forEach(function(button) {
|
||||||
setupSubmitButton(button);
|
setupSubmitButton(button);
|
||||||
});
|
});
|
||||||
|
|
||||||
massInputForm.addEventListener('submit', massInputFormSubmitHandler);
|
massInputForm.addEventListener('submit', massInputFormSubmitHandler);
|
||||||
|
massInputForm.addEventListener('keypress', keypressHandler);
|
||||||
|
|
||||||
// mark initialized
|
// mark initialized
|
||||||
element.classList.add(MASS_INPUT_INITIALIZED_CLASS);
|
element.classList.add(MASS_INPUT_INITIALIZED_CLASS);
|
||||||
@ -88,12 +87,8 @@
|
|||||||
var activeElement;
|
var activeElement;
|
||||||
|
|
||||||
// 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. a child is focused/active)
|
||||||
if (event.type === 'click') {
|
activeElement = element.querySelector(':focus, :active');
|
||||||
activeElement = event.target;
|
|
||||||
} else {
|
|
||||||
activeElement = element.querySelector(':focus, :active');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!activeElement) {
|
if (!activeElement) {
|
||||||
return false;
|
return false;
|
||||||
@ -140,6 +135,16 @@
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function keypressHandler(event) {
|
||||||
|
if (event.keyCode !== 13) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (massInputFormSubmitHandler) {
|
||||||
|
return massInputFormSubmitHandler(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function getMassInputSubmitButtons() {
|
function getMassInputSubmitButtons() {
|
||||||
return Array.from(element.querySelectorAll('button[type="submit"][name][value], .' + MASS_INPUT_SUBMIT_BUTTON_CLASS));
|
return Array.from(element.querySelectorAll('button[type="submit"][name][value], .' + MASS_INPUT_SUBMIT_BUTTON_CLASS));
|
||||||
}
|
}
|
||||||
@ -208,6 +213,7 @@
|
|||||||
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)
|
||||||
|
massInputForm.removeEventListener('keypress', keypressHandler);
|
||||||
|
|
||||||
var buttons = getMassInputSubmitButtons();
|
var buttons = getMassInputSubmitButtons();
|
||||||
buttons.forEach(function(button) {
|
buttons.forEach(function(button) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user