Hide/show div acting on keyup filter input
Date : March 29 2020, 07:55 AM
will help you I have a script that works with a filter to display the current view of tr's in a table. Pretty simple...when you type in the filter, the table updates based on that query and returns the corresponding amount: Displaying 25 results for Search: ________ (the number changes). I then have a div included at the end of that statement that just reflects the text put into the filter: Displaying 25 results for Search: _______ and Filter "blah". I am looking to be able to hide that div when the filter text is deleted from the filter...the filter is deactivated. As of now, it will clear the actual text blah but leave the rest of the div and Filter " ". , You just need to check whether the input value is empty or not: $('#filterText').html($(this).val() ? 'and Filter = "' + $('#filter').val()+'"' : '');
|
Keyup-Event added to eventlistener of HTML-input doesn't fire on keyup
Date : March 29 2020, 07:55 AM
wish of those help I'm working on an Ionic-tabs-app. In one of my templates i got a div - called "div_mask_content" - in which i load a mask - containing some labels and inputs - by setting the InnerHtml-property of the div. Because the div is reparsed after setting the InnerHtml-property i have to renew the keyup-event of the input-elements like this: , this will work: element.addEventListener('keyup', $scope.onKeyUp);
<input ng-keyup="onKeyUp()" />
|
EventListener keydown is working but keyup isn't
Date : March 29 2020, 07:55 AM
To fix this issue This is because alert() is script blocking. This means that whatever script you were running when it has been called is paused at this call, until the user close the alert (same for all other prompt windows). var Keys = [];
var FrameLoop = window.requestAnimationFrame ||
window.webkitrequestAnimationFrame || window.mozrequestAnimationFrame ||
window.msrequestAnimationFrame;
window.requestAnimationFrame = FrameLoop;
window.onload = GameChange();
function GameChange() {
if (Keys[39] == true) {
console.log("right");
}
FrameLoop(GameChange);
}
document.body.addEventListener("keydown", function(k) {
Keys[k.keyCode] = true;
});
document.body.addEventListener("keyup", function(k) {
Keys[k.keyCode] = false;
console.log('keyup');
});
onfocus = function(){document.body.className="focus"};
onblur = function(){document.body.className=""};
.focus > p {opacity: 0}
<p>click here to gain focus</p>
|
Getting the nested li from eventlistener 'keyup'
Date : March 29 2020, 07:55 AM
it fixes the issue I have a nested li which is editable. How can I get the particular li when there is 'keyup' event happened on that li. No jQuery please. , Your comment caught my attention... 'use strict';
let ul1 = document.createElement('ul');
ul1.id = 'numberList';
let li1 = document.createElement('li');
li1.innerHTML = 'one';
li1.id = 'li1';
let ul2 = document.createElement('ul');
ul2.id = 'ul2';
let li2 = document.createElement('li');
li2.innerHTML = 'two';
li2.id = 'li2';
let ul3 = document.createElement('ul');
ul3.id = 'ul3';
let li3 = document.createElement('li');
li3.innerHTML = 'four';
li3.id = 'li3';
li3.contentEditable = true;
li3.addEventListener('keyup', handler);
function handler(e){
if(e.type === 'keyup'){
console.log( this.id );
}
}
ul3.appendChild( li3 );
li2.appendChild( ul3 );
ul2.appendChild( li2 );
li1.appendChild( ul2 );
ul1.appendChild( li1 );
document.body.appendChild( ul1 );
|
what event (change, keyup, etc.) should I choose to filter data from an array using an input text using a optimal way
Date : March 29 2020, 07:55 AM
will help you RxJS's observables with debounceTime(), distinctUntilChanged(), and switchMap() operators can be used to do this optimally. This approach ensures that data isn't filtered on every key press (waits for given time and groups characters), ignores filtering again when same key is entered immediately, and has other advantages. <input [ngModel]="filterKey" (ngModelChange)="onFilterKeyChange($event)">
filterKey: string;
inputs$ = new Subject<any>();
onFilterKeyChange(key) {
this.filterKey = key;
this.inputs$.next({ 'filterKey': this.filterKey });
}
inputs$.pipe(
debounceTime(750), // Waits until there is no new data for given time.
distinctUntilChanged( // Only allows distinct data to pass through.
(p, q) => p.filterKey === q.filterKey
),
switchMap(input => {
// Has cancelling effect, ignores previous input when new key is entered.
let key = input.filterKey.trim();
// Filter the data.
let result = this.items.filter(item =>
item.toLowerCase().includes(key.toLowerCase())
);
return of(result);
})
.subscribe((result) => {
this.filteredData = result;
});
.switchMap((input) => {
let key = input.filterKey.trim();
return dataService.getFilteredData(key);
})
|