From 53bc77c42f9ade1b476512c3500ed85ac9a96011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20Fie=C3=9Finger?= <41627893+bfiessinger@users.noreply.github.com> Date: Sat, 28 Aug 2021 15:27:17 +0200 Subject: [PATCH] fix cascading livewire select inputs nulled after repainting (closes #18) --- resources/views/select.blade.php | 2 +- src/LivewireSelect.php | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/resources/views/select.blade.php b/resources/views/select.blade.php index 18adc57..6d98915 100644 --- a/resources/views/select.blade.php +++ b/resources/views/select.blade.php @@ -1,6 +1,6 @@
-
+
@if(!$searchable && $shouldShow) @include($defaultView, [ 'name' => $name, diff --git a/src/LivewireSelect.php b/src/LivewireSelect.php index 3422f70..3b7ea45 100755 --- a/src/LivewireSelect.php +++ b/src/LivewireSelect.php @@ -32,6 +32,7 @@ class LivewireSelect extends Component public $placeholder; public $value; + public $initValueEncoded; public $optionsValues; public $searchable; @@ -75,6 +76,7 @@ public function mount($name, $this->placeholder = $placeholder; $this->value = $value; + $this->initValueEncoded = json_encode($value); $this->searchable = $searchable; $this->searchTerm = ''; @@ -119,7 +121,7 @@ public function options($searchTerm = null) : Collection public function selectedOption($value) { - return null; + return $value; } public function notifyValueChanged() @@ -248,6 +250,7 @@ public function render() return view($this->selectView) ->with([ + 'initValueEncoded' => $this->initValueEncoded, 'options' => $options, 'selectedOption' => $selectedOption ?? null, 'shouldShow' => $shouldShow,