fix search problem - only if input is not empty change to search hash location (#9434)

This commit is contained in:
Piotr Żuralski 2019-05-11 18:44:20 +02:00 committed by Fabian Affolter
parent 06e7c7f8f1
commit 9e654ff3c6

View File

@ -61,7 +61,7 @@ Support for these components is provided by the Home Assistant community.
<div class="grid__item five-sixths lap-one-whole palm-one-whole">
<div class="component-search">
<form onsubmit="event.preventDefault(); return false">
<input type="text" name="search" id="search" class="search" placeholder="Search components...">
<input type="text" name="search" id="search" class="search" placeholder="Search components..." autofocus />
</form>
</div>
<div class="hass-option-cards" id="componentContainer"> </div>
@ -265,9 +265,11 @@ allComponents.pop(); // remove placeholder element at the end
$('.component-search input').keyup(debounce(function() {
var text = $(this).val();
// sanitize input
text = text.replace(/[(\?|\&\{\}\(\))]/gi, '');
text = text.replace(/[(\?|\&\{\}\(\))]/gi, '').trim();
if (typeof text === "string" && text.length !== 0) {
updateHash('#search/' + text);
applyFilter();
}
}, 500));
window.addEventListener('hashchange', applyFilter);