submit form when enter is pressed in an autocomplete text area
This commit is contained in:
parent
46d11a0be5
commit
12ca708be8
1 changed files with 8 additions and 3 deletions
|
@ -228,17 +228,22 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
highlightCompletion(element, element.selected_completion-1);
|
highlightCompletion(element, element.selected_completion-1);
|
||||||
}
|
}
|
||||||
if(event.code === "ArrowDown") {
|
else if(event.code === "ArrowDown") {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
highlightCompletion(element, element.selected_completion+1);
|
highlightCompletion(element, element.selected_completion+1);
|
||||||
}
|
}
|
||||||
// if enter or right are pressed, add the selected completion
|
// if enter or right are pressed, add the selected completion
|
||||||
if((event.code === "Enter" || event.code == "ArrowRight") && element.selected_completion !== -1) {
|
else if((event.code === "Enter" || event.code == "ArrowRight") && element.selected_completion !== -1) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
setCompletion(element, Object.keys(element.completions)[element.selected_completion]);
|
setCompletion(element, Object.keys(element.completions)[element.selected_completion]);
|
||||||
}
|
}
|
||||||
|
// If enter is pressed while nothing is selected, submit the form
|
||||||
|
else if(event.code === "Enter" && element.selected_completion === -1) {
|
||||||
|
event.preventDefault();
|
||||||
|
element.form.submit();
|
||||||
|
}
|
||||||
// if escape is pressed, hide the completion block
|
// if escape is pressed, hide the completion block
|
||||||
if(event.code === "Escape") {
|
else if(event.code === "Escape") {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
hideCompletions();
|
hideCompletions();
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue