move massinput js logic to shakespeare widget
This commit is contained in:
parent
2d67bec956
commit
1aa54636b6
@ -197,31 +197,4 @@
|
||||
if (UtilRegistry) {
|
||||
inputUtilities.forEach(UtilRegistry.register);
|
||||
}
|
||||
|
||||
// FH: leaving this as it is to be able to understand whats going on
|
||||
|
||||
// Override implicit submit (pressing enter) behaviour to trigger a specified submit button instead of the default
|
||||
window.utils.implicitSubmit = function(input, options) {
|
||||
var submit = options.submit;
|
||||
|
||||
if (!submit) {
|
||||
throw new Error('window.utils.implicitSubmit(input, options) needs to be passed a submit element via options');
|
||||
}
|
||||
|
||||
var doSubmit = function(event) {
|
||||
if (event.keyCode == 13) {
|
||||
event.preventDefault();
|
||||
submit.click();
|
||||
}
|
||||
};
|
||||
|
||||
input.addEventListener('keypress', doSubmit);
|
||||
|
||||
return {
|
||||
scope: input,
|
||||
destroy: function() {
|
||||
input.removeEventListener('keypress', doSubmit);
|
||||
},
|
||||
};
|
||||
}
|
||||
})();
|
||||
|
||||
@ -6,7 +6,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
var cellInputs = Array.from(form.querySelectorAll('.massinput--cell input:not([type=hidden])'));
|
||||
|
||||
cellInputs.forEach(function(input) {
|
||||
window.utils.setup('implicitSubmit', input, { submit: formSubmit });
|
||||
makeImplicitSubmit(input, formSubmit);
|
||||
});
|
||||
|
||||
|
||||
@ -15,7 +15,23 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
var addInputs = Array.from(wrapper.querySelectorAll('input:not([type=hidden]):not(.btn-mass-input-add)'));
|
||||
|
||||
addInputs.forEach(function(input) {
|
||||
window.utils.setup('implicitSubmit', input, { submit: addSubmit });
|
||||
makeImplicitSubmit(input, addSubmit);
|
||||
});
|
||||
});
|
||||
|
||||
// Override implicit submit (pressing enter) behaviour to trigger a specified submit button instead of the default
|
||||
function makeImplicitSubmit(input, submit) {
|
||||
if (!submit) {
|
||||
throw new Error('implicitSubmit(input, options) needs to be passed a submit element via options');
|
||||
}
|
||||
|
||||
var doSubmit = function(event) {
|
||||
if (event.keyCode == 13) {
|
||||
event.preventDefault();
|
||||
submit.click();
|
||||
}
|
||||
};
|
||||
|
||||
input.addEventListener('keypress', doSubmit);
|
||||
}
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user