mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-24 15:42:09 +08:00
fix: Prevent hidden builder fields from breaking repeaters (#19676)
* test: add test for saving builder block with repeater and hidden field * fix: Prevent hidden builder fields from breaking repeaters
This commit is contained in:
@@ -381,11 +381,17 @@ trait HasState
|
||||
$container = $this->getContainer();
|
||||
|
||||
while ($parentComponent = $container->getParentComponent()) {
|
||||
$parentContainer = $parentComponent->getContainer();
|
||||
|
||||
if ($parentComponent->hasStatePath()) {
|
||||
break;
|
||||
}
|
||||
|
||||
$container = $parentComponent->getContainer();
|
||||
if ($parentContainer->getStatePath() !== $container->getStatePath()) {
|
||||
break;
|
||||
}
|
||||
|
||||
$container = $parentContainer;
|
||||
}
|
||||
|
||||
foreach ($container->getFlatComponents(withActions: false, withHidden: true) as $component) {
|
||||
|
||||
@@ -278,6 +278,13 @@ it('can access correct block state from `extraItemActions()`', function (): void
|
||||
$undoBuilderFake();
|
||||
});
|
||||
|
||||
it('can save a builder block containing a repeater and hidden field', function (): void {
|
||||
livewire(TestComponentWithBuilderRepeaterAndHiddenField::class)
|
||||
->assertSuccessful()
|
||||
->call('save')
|
||||
->assertHasNoFormErrors();
|
||||
});
|
||||
|
||||
class TestComponentWithActionInBuilder extends Livewire
|
||||
{
|
||||
public function mount(): void
|
||||
@@ -342,6 +349,47 @@ class TestComponentWithExtraItemActionInBuilder extends Livewire
|
||||
}
|
||||
}
|
||||
|
||||
class TestComponentWithBuilderRepeaterAndHiddenField extends Livewire
|
||||
{
|
||||
public function form(Schema $form): Schema
|
||||
{
|
||||
return $form
|
||||
->components([
|
||||
Builder::make('builder')
|
||||
->blocks([
|
||||
Builder\Block::make('services')
|
||||
->schema([
|
||||
Repeater::make('items')
|
||||
->schema([
|
||||
TextInput::make('service')
|
||||
->required(),
|
||||
]),
|
||||
TextInput::make('hidden')
|
||||
->visible(false),
|
||||
]),
|
||||
])
|
||||
->default([
|
||||
[
|
||||
'type' => 'services',
|
||||
'data' => [
|
||||
'items' => [
|
||||
[
|
||||
'service' => 'Service 1',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
]),
|
||||
])
|
||||
->statePath('data');
|
||||
}
|
||||
|
||||
public function save(): void
|
||||
{
|
||||
$this->form->getState();
|
||||
}
|
||||
}
|
||||
|
||||
describe('properties', function (): void {
|
||||
it('can set `addActionLabel()` and get with `getAddActionLabel()`', function (): void {
|
||||
$builder = Builder::make('content')
|
||||
|
||||
Reference in New Issue
Block a user