#30 autofocus #add_coin_name input#name, bind ENTER to submit
This commit is contained in:
parent
9a1a060f49
commit
aa585503dc
@ -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']
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user