mirror of
https://github.com/oupala/apaxy.git
synced 2026-02-28 01:01:04 +01:00
feat: filter auto select on key down
Filter input gets focus on keydown. On page back filter the list if input is not empty.
This commit is contained in:
@@ -60,6 +60,23 @@
|
||||
document.addEventListener('readystatechange', function() {
|
||||
if (document.readyState === 'complete') {
|
||||
TableFilter.init();
|
||||
var filterInput = document.getElementById('filter');
|
||||
if ( filterInput.value.trim().length ){
|
||||
filterInput.focus();
|
||||
filterInput.dispatchEvent(new Event('input'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Use Keydown to get special keys like Backspace, Enter, Esc.
|
||||
window.addEventListener('keydown', function (e) {
|
||||
var filterInput = document.getElementById('filter');
|
||||
var isFocused = (document.activeElement === filterInput);
|
||||
if ( !isFocused && String.fromCharCode(e.keyCode).match(/(\w|\s)/g) ) {
|
||||
filterInput.focus();
|
||||
} else {
|
||||
//pressed key is a non-char
|
||||
//e.g. 'esc', 'backspace', 'up arrow'
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user