Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

Commit cdcc979

Browse files
Ghislain BeaulacGhislain Beaulac
Ghislain Beaulac
authored and
Ghislain Beaulac
committed
fix(filter): all jquery .on bound event should also be unbound
- the multiple-select.js was causing some weird behavior, if user would go on the GraphQL example, then choose a different company in the multiple select filter and click away (not on OK button) to simulate a blur, the spinner would never show up. The reason was because there was a click event bound to the document and was never unbound - ref wenzhixin/multiple-select#373
1 parent 9dda431 commit cdcc979

File tree

10 files changed

+43
-37
lines changed

10 files changed

+43
-37
lines changed

src/app/examples/custom-inputEditor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class CustomInputEditor implements Editor {
5757
}
5858

5959
destroy() {
60-
this.$input.remove();
60+
this.$input.off('keydown.nav').remove();
6161
}
6262

6363
focus() {

src/app/modules/angular-slickgrid/editors/autoCompleteEditor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export class AutoCompleteEditor implements Editor {
100100
}
101101

102102
destroy() {
103-
this.$input.remove();
103+
this.$input.off('keydown.nav').remove();
104104
}
105105

106106
focus() {

src/app/modules/angular-slickgrid/editors/floatEditor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class FloatEditor implements Editor {
6161
}
6262

6363
destroy() {
64-
this.$input.remove();
64+
this.$input.off('keydown.nav focusout').remove();
6565
}
6666

6767
focus() {

src/app/modules/angular-slickgrid/editors/integerEditor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class IntegerEditor implements Editor {
5959
}
6060

6161
destroy() {
62-
this.$input.remove();
62+
this.$input.off('keydown.nav focusout').remove();
6363
}
6464

6565
focus() {

src/app/modules/angular-slickgrid/editors/longTextEditor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export class LongTextEditor implements Editor {
137137
}
138138

139139
destroy() {
140-
this.$wrapper.remove();
140+
this.$wrapper.off('keydown focusout').remove();
141141
}
142142

143143
focus() {

src/app/modules/angular-slickgrid/editors/sliderEditor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class SliderEditor implements Editor {
7272
}
7373

7474
destroy() {
75-
this.$editorElm.remove();
75+
this.$editorElm.off('input change mouseup').remove();
7676
}
7777

7878
focus() {

src/app/modules/angular-slickgrid/editors/textEditor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export class TextEditor implements Editor {
5858
}
5959

6060
destroy() {
61-
this.$input.remove();
61+
this.$input.off('keydown.nav focusout').remove();
6262
}
6363

6464
focus() {

src/app/modules/angular-slickgrid/filters/compoundSliderFilter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export class CompoundSliderFilter implements Filter {
123123
*/
124124
destroy() {
125125
if (this.$filterElm) {
126-
this.$filterElm.off('change').remove();
126+
this.$filterElm.off('input change').remove();
127127
}
128128
}
129129

src/app/modules/angular-slickgrid/services/filter.service.ts

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Injectable } from '@angular/core';
22
import {
3+
BackendServiceApi,
34
Column,
45
ColumnFilter,
56
ColumnFilters,
@@ -72,11 +73,11 @@ export class FilterService {
7273
this._slickSubscriber = new Slick.Event();
7374

7475
// subscribe to the SlickGrid event and call the backend execution
75-
this._slickSubscriber.subscribe(this.attachBackendOnFilterSubscribe.bind(this));
76+
this._slickSubscriber.subscribe(this.onBackendFilterChange.bind(this));
7677

7778
// subscribe to SlickGrid onHeaderRowCellRendered event to create filter template
7879
this._eventHandler.subscribe(grid.onHeaderRowCellRendered, (e: KeyboardEvent, args: any) => {
79-
// firstColumnIdRendered is null at first, so if becomes filled and equal then we know it was already rendered
80+
// firstColumnIdRendered is null at first, so if it changes to being filled and equal then we know it was already rendered
8081
if (args.column.id === this._firstColumnIdRendered) {
8182
this._isFilterFirstRender = false;
8283
}
@@ -87,7 +88,7 @@ export class FilterService {
8788
});
8889
}
8990

90-
async attachBackendOnFilterSubscribe(event: KeyboardEvent, args: any) {
91+
onBackendFilterChange(event: KeyboardEvent, args: any) {
9192
if (!args || !args.grid) {
9293
throw new Error('Something went wrong when trying to attach the "attachBackendOnFilterSubscribe(event, args)" function, it seems that "args" is not populated correctly');
9394
}
@@ -111,31 +112,37 @@ export class FilterService {
111112
}
112113

113114
// call the service to get a query back
114-
clearTimeout(timer);
115-
timer = setTimeout(async () => {
116-
const query = await backendApi.service.processOnFilterChanged(event, args);
117-
118-
// emit an onFilterChanged event when it's not called by clearAllFilters
119-
if (args && !args.clearFilterTriggered) {
120-
this.emitFilterChanged('remote');
121-
}
122-
123-
// the processes can be Observables (like HttpClient) or Promises
124-
const process = backendApi.process(query);
125-
if (process instanceof Promise && process.then) {
126-
process.then((processResult: GraphqlResult | any) => executeBackendProcessesCallback(startTime, processResult, backendApi, this._gridOptions));
127-
} else if (isObservable(process)) {
128-
process.subscribe(
129-
(processResult: GraphqlResult | any) => executeBackendProcessesCallback(startTime, processResult, backendApi, this._gridOptions),
130-
(error: any) => onBackendError(error, backendApi)
131-
);
132-
}
133-
}, debounceTypingDelay);
115+
if (debounceTypingDelay > 0) {
116+
clearTimeout(timer);
117+
timer = setTimeout(() => this.executeBackendCallback(args, startTime, backendApi), debounceTypingDelay);
118+
} else {
119+
this.executeBackendCallback(args, startTime, backendApi);
120+
}
134121
} catch (error) {
135122
onBackendError(error, backendApi);
136123
}
137124
}
138125

126+
async executeBackendCallback(args: any, startTime: Date, backendApi: BackendServiceApi) {
127+
const query = await backendApi.service.processOnFilterChanged(event, args);
128+
129+
// emit an onFilterChanged event when it's not called by clearAllFilters
130+
if (args && !args.clearFilterTriggered) {
131+
this.emitFilterChanged('remote');
132+
}
133+
134+
// the processes can be Observables (like HttpClient) or Promises
135+
const process = backendApi.process(query);
136+
if (process instanceof Promise && process.then) {
137+
process.then((processResult: GraphqlResult | any) => executeBackendProcessesCallback(startTime, processResult, backendApi, this._gridOptions));
138+
} else if (isObservable(process)) {
139+
process.subscribe(
140+
(processResult: GraphqlResult | any) => executeBackendProcessesCallback(startTime, processResult, backendApi, this._gridOptions),
141+
(error: any) => onBackendError(error, backendApi)
142+
);
143+
}
144+
}
145+
139146
/**
140147
* Attach a local filter hook to the grid
141148
* @param grid SlickGrid Grid object
@@ -395,7 +402,7 @@ export class FilterService {
395402
}
396403

397404
// trigger an event only if Filters changed or if ENTER key was pressed
398-
const eventKeyCode = e && e.keyCode && e.keyCode;
405+
const eventKeyCode = e && e.keyCode;
399406
if (eventKeyCode === KeyCode.ENTER || !isequal(oldColumnFilters, this._columnFilters)) {
400407
this.triggerEvent(this._slickSubscriber, {
401408
clearFilterTriggered: args && args.clearFilterTriggered,
@@ -460,7 +467,7 @@ export class FilterService {
460467
}
461468

462469
/**
463-
* A simple function that is attached to the subscriber and emit a change when the sort is called.
470+
* A simple function that is attached to the subscriber and emit a change when the filter is called.
464471
* Other services, like Pagination, can then subscribe to it.
465472
* @param caller
466473
*/

src/assets/lib/multiple-select/multiple-select.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,15 @@
209209
this.selectItemName = 'data-name="selectItem' + name + '"';
210210

211211
if (!this.options.keepOpen) {
212-
$(document).click(function (e) {
212+
$(document).off('click').click(function (e) {
213213
if ($(e.target)[0] === that.$choice[0] ||
214214
$(e.target).parents('.ms-choice')[0] === that.$choice[0]) {
215215
return;
216216
}
217217
if (($(e.target)[0] === that.$drop[0] ||
218218
$(e.target).parents('.ms-drop')[0] !== that.$drop[0] && e.target !== $el[0]) &&
219-
that.options.isOpen) {
219+
that.options.isOpen
220+
) {
220221
that.close();
221222
}
222223
});
@@ -264,8 +265,6 @@
264265
if (this.options.okButton) {
265266
this.$okButton = $('<button type="button" class="ms-ok-button">' + this.options.okButtonText + '</button>');
266267
this.$drop.append(this.$okButton);
267-
268-
269268
}
270269

271270
var dropWidth = isNaN(this.options.width) ? this.options.width : this.options.width + 'px';

0 commit comments

Comments
 (0)