#30 autofocus #add_coin_name input#name, bind ENTER to submit

This commit is contained in:
koksnuss 2020-05-19 10:20:12 +02:00
parent 9a1a060f49
commit aa585503dc
2 changed files with 17 additions and 9 deletions

View File

@ -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']

View File

@ -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 #<modal_name>_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);
}
}