Capture enter key to submit form

This commit is contained in:
Oliver 2021-07-02 17:19:58 +10:00
parent 72526307ae
commit 047b9d1ecd

View File

@ -53,11 +53,33 @@ function createNewModal(options={}) {
var modal_name = `#modal-form-${id}`;
$(modal_name).on('shown.bs.modal', function() {
$(modal_name + ' .modal-form-content').scrollTop(0);
});
// Automatically remove the modal when it is deleted!
$(modal_name).on('hidden.bs.modal', function(e) {
$(modal_name).remove();
});
// Capture "enter" key input
$(modal_name).on('keydown', 'input', function(event) {
if (event.keyCode == 13) {
event.preventDefault();
// Simulate a click on the 'Submit' button
$(modal_name).find("#modal-form-submit").click();
return false;
}
});
$(modal_name).modal({
backdrop: 'static',
keyboard: false,
});
// Set labels based on supplied options
modalSetTitle(modal_name, options.title || '{% trans "Form Title" %}');
modalSetSubmitText(modal_name, options.submitText || '{% trans "Submit" %}');