Extend Component, set optional schema based on flag
I have moved complex schema sections to new classes, which I then include in the resource. In the extended component I set up the schema for fields. This works nicely and I am able to override things such as the heading that was set in the custom component.
I can't work out how to conditionally make visible/hidden components.
```php
// In the resource I want MyCustomSection::make()->heading('Example')->simple();
class MyCustomSection extends Section
{
protected bool $simple = false;
public function simple()
{
$this->simple = true;
}
protected function setUp(): void
{
parent::setUp();
$this
->heading(class_basename(static::class))
->schema([
... //more fields
DatePicker::make('modified')->hidden($this->simple),
]);
}
}
3 Replies
Where does the parent push data too? We usually use the closure so $get('simple', false) and on updating a toggle for simple = true you would put a reactive and afterStateUpdated $set('simple', true)
Parent is just the base
Section
component.Solution
I moved the check to
afterStateHydrated
and it worked. π