#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();
|
modal.show();
|
||||||
|
|
||||||
function add_user(args='', response='') {
|
function add_user(args='', response='') {
|
||||||
console.log(response);
|
|
||||||
let name = encodeURIComponent(response['name']
|
let name = encodeURIComponent(response['name']
|
||||||
.trim().substring(0, 19).replace(' ', '-'));
|
.trim().substring(0, 19).replace(' ', '-'));
|
||||||
let color = encodeURIComponent(response['color']
|
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)
|
$(document)
|
||||||
.bind('keypress', {this: this}, function(event) {
|
.bind('keypress', {this: this}, function(event) {
|
||||||
if (event.keyCode == 27) {
|
if (event.keyCode == 27) {
|
||||||
hide(event.data.this.modal);
|
hide(event.data.this.modal);
|
||||||
$(document).off('keypress');
|
$(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 */
|
/* trigger callback on button #<modal_name>_action */
|
||||||
$('#' + this.modal + '_action')
|
$('#' + this.modal + '_action')
|
||||||
.bind('click', {this: this}, function(event) {
|
.bind('click', {this: this}, function(event) {
|
||||||
let scope = event.data.this;
|
event.data.this.submit();
|
||||||
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);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/* 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