Skip to content

Commit 2aeb882

Browse files
authored
Fix BooleanColumn unexpected truthy behaviour (rappasoft#2066)
* Fix BooleanColumn unexpected truthy behaviour * Support previous iteration
1 parent a9afdd8 commit 2aeb882

File tree

3 files changed

+49
-13
lines changed

3 files changed

+49
-13
lines changed

resources/js/laravel-livewire-tables.js

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ document.addEventListener('alpine:init', () => {
250250

251251
}
252252
}));
253-
254253

255254
Alpine.data('booleanFilter', (wire,filterKey,tableName,defaultValue) => ({
256255
switchOn: false,
@@ -270,6 +269,47 @@ document.addEventListener('alpine:init', () => {
270269
}
271270
}));
272271

272+
Alpine.data('newBooleanFilter', (filterKey,tableName,defaultValue) => ({
273+
switchOn: false,
274+
value: false,
275+
toggleStatus()
276+
{
277+
let tempValue = Boolean(Number(this.$wire.get('filterComponents.'+filterKey) ?? this.value));
278+
let newBoolean = !tempValue;
279+
this.switchOn = this.value = newBoolean;
280+
return Number(newBoolean);
281+
},
282+
toggleStatusWithUpdate()
283+
{
284+
let newValue = this.toggleStatus();
285+
this.$wire.set('filterComponents.'+filterKey, newValue);
286+
},
287+
toggleStatusWithReset()
288+
{
289+
let newValue = this.toggleStatus();
290+
this.$wire.call('resetFilter',filterKey);
291+
},
292+
setSwitchOn(val)
293+
{
294+
let number = Number(val ?? 0);
295+
this.switchOn = Boolean(number);
296+
},
297+
init() {
298+
this.$nextTick(() => {
299+
this.value = this.$wire.get('filterComponents.'+filterKey) ?? defaultValue;
300+
this.setSwitchOn(this.value ?? 0);
301+
});
302+
303+
this.listeners.push(
304+
Livewire.on('filter-was-set', (detail) => {
305+
if(detail.tableName == tableName && detail.filterKey == filterKey) {
306+
this.switchOn = detail.value ?? defaultValue;
307+
}
308+
})
309+
);
310+
}
311+
}));
312+
273313
Alpine.data('numberRangeFilter', (wire, filterKey, parentElementPath, filterConfig, childElementRoot) => ({
274314
allFilters: wire.entangle('filterComponents', false),
275315
originalMin: 0,
@@ -407,7 +447,6 @@ document.addEventListener('alpine:init', () => {
407447

408448
}));
409449

410-
411450
Alpine.data('tableWrapper', (wire, showBulkActionsAlpine) => ({
412451
shouldBeDisplayed: wire.entangle('shouldBeDisplayed'),
413452
listeners: [],

0 commit comments

Comments
 (0)