diff --git a/coinmanager/coinc/static/coinc/main.js b/coinmanager/coinc/static/coinc/main.js index 78df12a..876479f 100644 --- a/coinmanager/coinc/static/coinc/main.js +++ b/coinmanager/coinc/static/coinc/main.js @@ -386,7 +386,6 @@ $(document).ready(function() { modal.show(); function add_user(args='', response='') { - console.log(response); let name = encodeURIComponent(response['name'] .trim().substring(0, 19).replace(' ', '-')); let color = encodeURIComponent(response['color'] diff --git a/coinmanager/coinc/static/coinc/modules/modal.mjs b/coinmanager/coinc/static/coinc/modules/modal.mjs index 9c00206..3731d8e 100644 --- a/coinmanager/coinc/static/coinc/modules/modal.mjs +++ b/coinmanager/coinc/static/coinc/modules/modal.mjs @@ -50,12 +50,14 @@ class Modal { } }); - /* close modal on keypress ESC */ + /* close modal on keypress ESC, send modal on keypress ENTER */ $(document) .bind('keypress', {this: this}, function(event) { if (event.keyCode == 27) { hide(event.data.this.modal); $(document).off('keypress'); + } else if (event.keyCode == 13) { + event.data.this.submit(); } }); @@ -68,14 +70,21 @@ class Modal { /* trigger callback on button #_action */ $('#' + this.modal + '_action') .bind('click', {this: this}, function(event) { - let scope = event.data.this; - let response = {}; - $('#' + scope.modal + ' input[type=text]').each(function() { - response[$(this).attr('name')] = $(this).val(); - // TODO i thonk we dont need .get() here, as we dont save the output - }).get(); - scope.callback(scope.callback_arguments, response); + event.data.this.submit(); }); + + /* focus first input text element */ + $('#' + this.modal + ' input:text:visible:first').focus(); + } + + + /*submit modal */ + submit() { + let response = {}; + $('#' + this.modal + ' input[type=text]').each(function() { + response[$(this).attr('name')] = $(this).val(); + }); + this.callback(this.callback_arguments, response); } }