F
Filamentβ€’15mo ago
trovster

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), ]); } }
Solution:
I moved the check to afterStateHydrated and it worked. πŸ™‚
Jump to solution
3 Replies
toeknee
toekneeβ€’15mo ago
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)
trovster
trovsterOPβ€’15mo ago
Parent is just the base Section component.
Solution
trovster
trovsterβ€’15mo ago
I moved the check to afterStateHydrated and it worked. πŸ™‚
Want results from more Discord servers?
Add your server