mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-24 15:42:09 +08:00
Merge pull request #16295 from alanost/test/dehydration-hidden-fields
Hidden fields incorrectly dehydrated in Section with state path
This commit is contained in:
@@ -186,16 +186,12 @@ trait HasState
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->getStatePath(isAbsolute: false)) {
|
||||
if ($this->hasStatePath()) {
|
||||
foreach ($this->getStateToDehydrate() as $key => $value) {
|
||||
Arr::set($state, $key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->isHiddenAndNotDehydrated()) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($this->getChildComponentContainers(withHidden: true) as $container) {
|
||||
$container->dehydrateState($state, $isDehydrated);
|
||||
}
|
||||
@@ -438,7 +434,11 @@ trait HasState
|
||||
|
||||
public function isDehydrated(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->isDehydrated);
|
||||
if (! $this->evaluate($this->isDehydrated)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ! $this->isHiddenAndNotDehydrated();
|
||||
}
|
||||
|
||||
public function isDehydratedWhenHidden(): bool
|
||||
|
||||
@@ -72,10 +72,6 @@ trait HasState
|
||||
public function dehydrateState(array &$state = [], bool $isDehydrated = true): array
|
||||
{
|
||||
foreach ($this->getComponents(withHidden: true) as $component) {
|
||||
if ($component->isHiddenAndNotDehydrated()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$component->dehydrateState($state, $isDehydrated);
|
||||
}
|
||||
|
||||
@@ -89,10 +85,6 @@ trait HasState
|
||||
public function mutateDehydratedState(array &$state = []): array
|
||||
{
|
||||
foreach ($this->getComponents(withHidden: true) as $component) {
|
||||
if ($component->isHiddenAndNotDehydrated()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! $component->isDehydrated()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
use Filament\Forms\ComponentContainer;
|
||||
use Filament\Forms\Components\Component;
|
||||
use Filament\Forms\Components\Placeholder;
|
||||
use Filament\Forms\Components\Radio;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Get;
|
||||
use Filament\Tests\Forms\Fixtures\Livewire;
|
||||
use Filament\Tests\TestCase;
|
||||
@@ -508,6 +511,29 @@ test('hidden components are excluded from state dehydration except if they are m
|
||||
->dehydrateState()->not()->toBe([]);
|
||||
});
|
||||
|
||||
test('hidden components are excluded from state dehydration even if their parent component has a state path', function () {
|
||||
$container = ComponentContainer::make(Livewire::make())
|
||||
->statePath('data')
|
||||
->components([
|
||||
(new Component)
|
||||
->statePath('nested')
|
||||
->schema([
|
||||
(new Component)
|
||||
->statePath(Str::random())
|
||||
->default(Str::random())
|
||||
->hidden(),
|
||||
]),
|
||||
])
|
||||
->fill();
|
||||
|
||||
expect($container)
|
||||
->dehydrateState()->toBe([
|
||||
'data' => [
|
||||
'nested' => [],
|
||||
],
|
||||
]);
|
||||
});
|
||||
|
||||
test('disabled components are excluded from state dehydration', function () {
|
||||
$container = ComponentContainer::make(Livewire::make())
|
||||
->statePath('data')
|
||||
|
||||
Reference in New Issue
Block a user