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

Commit 185bf01

Browse files
committed
Force custom select null values to update with wire:model.defer
1 parent 0f1e70c commit 185bf01

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

resources/js/mixins/select.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export default {
3131
_wireToggleMethod: '',
3232
_focusedOptionId: null,
3333
_noCloseOnSelect: false, // flag we can set for certain actions that shouldn't close the menu
34+
_wireModelName: null,
3435

3536
menu() {
3637
if (! this.$refs.menu) {
@@ -501,6 +502,13 @@ export default {
501502
this.handleValueChange();
502503

503504
this.$dispatch('input', newValue);
505+
506+
// For some reason when using a wire:model.defer, livewire is not
507+
// sending null values back to the server for updates, so we will
508+
// force it to here...
509+
if (newValue === null && this._wire && this._wireModelName) {
510+
this._wire.set(this._wireModelName, null, true);
511+
}
504512
});
505513
},
506514

resources/views/components/inputs/custom-select.blade.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
@endif
66
@if ($hasWireModel())
77
value: @entangle($attributes->wire('model')),
8+
@if ($attributes->wire('model')->hasModifier('defer'))
9+
_wireModelName: '{{ $attributes->wire('model')->value() }}',
10+
@endif
811
@elseif ($hasXModel())
912
value: {{ $attributes->first('x-model') }},
1013
@else

resources/views/components/inputs/tree-select.blade.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
@endif
66
@if ($hasWireModel())
77
value: @entangle($attributes->wire('model')),
8+
@if ($attributes->wire('model')->hasModifier('defer'))
9+
_wireModelName: '{{ $attributes->wire('model')->value() }}',
10+
@endif
811
@elseif ($hasXModel())
912
value: {{ $attributes->first('x-model') }},
1013
@else

0 commit comments

Comments
 (0)