Skip to content

Commit

Permalink
Merge pull request #9257 from tiagorodriguesnes/morph-to-select-broke…
Browse files Browse the repository at this point in the history
…n-after-state-updated

Fixes MorphToSelect afterStateUpdated, reactive and lazy.
  • Loading branch information
danharrin authored Oct 27, 2023
2 parents b169139 + 1cd382a commit ce90b28
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
11 changes: 9 additions & 2 deletions packages/forms/src/Components/MorphToSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ public function getChildComponents(): array
))
->required($isRequired)
->reactive()
->afterStateUpdated(fn (Closure $set) => $set($keyColumn, null)),
->afterStateUpdated(function (Closure $set) use ($keyColumn) {
$set($keyColumn, null);
$this->callAfterStateUpdated();
}),
Select::make($keyColumn)
->label($selectedType?->getLabel())
->disableLabel()
Expand All @@ -74,7 +77,11 @@ public function getChildComponents(): array
->loadingMessage($this->getLoadingMessage())
->allowHtml($this->isHtmlAllowed())
->optionsLimit($this->getOptionsLimit())
->preload($this->isPreloaded()),
->preload($this->isPreloaded())
->reactive($this->isReactive())
->afterStateUpdated(function () {
$this->callAfterStateUpdated();
}),
];
}

Expand Down
12 changes: 8 additions & 4 deletions packages/forms/src/Concerns/HasStateBindingModifiers.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,20 @@ trait HasStateBindingModifiers

protected string | int | null $debounce = null;

public function reactive(): static
public function reactive(bool $condition = true): static
{
$this->stateBindingModifiers([]);
if ($condition) {
$this->stateBindingModifiers([]);
}

return $this;
}

public function lazy(): static
public function lazy(bool $condition = true): static
{
$this->stateBindingModifiers(['lazy']);
if ($condition) {
$this->stateBindingModifiers(['lazy']);
}

return $this;
}
Expand Down

0 comments on commit ce90b28

Please sign in to comment.