Add auto search on autocomplete select

This commit is contained in:
Augusto Gunsch 2021-12-26 17:41:55 -03:00
parent 57338dc0ce
commit edeece9d7c
No known key found for this signature in database
GPG Key ID: F7EEFE29825C72DC
2 changed files with 12 additions and 5 deletions

View File

@ -18,7 +18,7 @@
<div class="ui-widget" id="search-widget"> <div class="ui-widget" id="search-widget">
<input id="search-bar" placeholder="Search..." type="text" autocorrect="off" autocapitalize="none" autofocus> <input id="search-bar" placeholder="Search..." type="text" autocorrect="off" autocapitalize="none" autofocus>
</div> </div>
<button type="submit" class="ui-button ui-widget ui-button-icon-only" id="search"> <button type="submit" class="ui-button ui-widget" id="search">
<span class="ui-icon ui-icon-search"></span> <span class="ui-icon ui-icon-search"></span>
</button> </button>
</form> </form>

View File

@ -23,13 +23,18 @@ $(document).ready(() => {
url: '/langs/polish/words?like=' + request.term + '&limit=20&offset=0', url: '/langs/polish/words?like=' + request.term + '&limit=20&offset=0',
success: data => response(data) success: data => response(data)
}) })
} },
select: (_, ui) => window.location.hash = ui.item.value
}); });
searchBar.on('focus', e => { searchBar.on('focus', e => {
setTimeout(() => e.currentTarget.select(), 100); setTimeout(() => e.currentTarget.select(), 100);
}); });
$(window).on('scroll', () => {
searchBar.autocomplete('close');
});
$('#search-form').on('submit', (e) => { $('#search-form').on('submit', (e) => {
e.preventDefault(); e.preventDefault();
@ -40,18 +45,20 @@ $(document).ready(() => {
function getWord() { function getWord() {
let word = window.location.hash.replace('#', ''); let word = window.location.hash.replace('#', '');
$.ajax({ $.ajax({
url: '/langs/polish/words/' + word, url: '/langs/polish/words/' + word,
success: (data) => { success: (data) => {
$('#ajax-content').html(generateHtml(word, data)) $('#ajax-content').html(generateHtml(word, data))
window.scrollTo(0, 0);
searchBar.select();
searchBar.autocomplete('close');
}, },
error: err => console.error(err) error: err => console.error(err)
}) })
window.scrollTo(0, 0);
searchBar.select();
searchBar.autocomplete('close');
} }
function getCells(forms, tags) { function getCells(forms, tags) {