Skip to content

Commit

Permalink
fix cascading livewire select inputs nulled after repainting (closes a…
Browse files Browse the repository at this point in the history
  • Loading branch information
bfiessinger committed Aug 28, 2021
1 parent 9bdc4f1 commit 53bc77c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion resources/views/select.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div>

<div>
<div x-init="$wire.set('value', {{ $initValueEncoded }})">
@if(!$searchable && $shouldShow)
@include($defaultView, [
'name' => $name,
Expand Down
5 changes: 4 additions & 1 deletion src/LivewireSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class LivewireSelect extends Component
public $placeholder;

public $value;
public $initValueEncoded;
public $optionsValues;

public $searchable;
Expand Down Expand Up @@ -75,6 +76,7 @@ public function mount($name,
$this->placeholder = $placeholder;

$this->value = $value;
$this->initValueEncoded = json_encode($value);

$this->searchable = $searchable;
$this->searchTerm = '';
Expand Down Expand Up @@ -119,7 +121,7 @@ public function options($searchTerm = null) : Collection

public function selectedOption($value)
{
return null;
return $value;
}

public function notifyValueChanged()
Expand Down Expand Up @@ -248,6 +250,7 @@ public function render()

return view($this->selectView)
->with([
'initValueEncoded' => $this->initValueEncoded,
'options' => $options,
'selectedOption' => $selectedOption ?? null,
'shouldShow' => $shouldShow,
Expand Down

0 comments on commit 53bc77c

Please sign in to comment.