Skip to content

Commit

Permalink
Merge pull request #3 from bfiessinger/fix/null-value-on-mount
Browse files Browse the repository at this point in the history
fix cascading livewire select inputs nulled after repainting
  • Loading branch information
bfiessinger authored Aug 28, 2021
2 parents 4fb8bf4 + 53bc77c commit 72dfb9e
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)
@if(!$multiple)
@include($defaultView, [
Expand Down
5 changes: 4 additions & 1 deletion src/LivewireSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class LivewireSelect extends Component
public $placeholder;

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

public $searchable;
Expand Down Expand Up @@ -81,6 +82,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 @@ -128,7 +130,7 @@ public function options($searchTerm = null) : Collection

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

public function notifyValueChanged()
Expand Down Expand Up @@ -359,6 +361,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 72dfb9e

Please sign in to comment.