F
Filamentβ€’16mo ago
ins1d3r_

Is it possible to prefill a block for a Builder component

Hi, I'm trying to make a Resource that has a Builder with blocks that contain their own builder with multiple blocks. Upon selecting a block from the first builder I want the block that appears to already contain a builder with 3 blocks that are be pre-filled with my data and visible when added. Is it possible and how to do it?
Solution:
You can use default()- just build your desired array structure there, e.g. `->default([ [ 'type' => 'text',...
Jump to solution
5 Replies
Patrick Boivin
Patrick Boivinβ€’16mo ago
I think this can be done by extending the 'add' action on the Builder field via ->addAction() You would need to reach into the call to fill() here: https://github.com/filamentphp/filament/blob/3.x/packages/forms/src/Components/Builder.php#L127
Solution
ajnsn
ajnsnβ€’16mo ago
You can use default()- just build your desired array structure there, e.g. ->default([ [ 'type' => 'text', 'data' => [ 'content' => 'Hello World', ], ], ]) Note content is just an example field within the block type "text.
Patrick Boivin
Patrick Boivinβ€’16mo ago
I don't think this will work per-block. But it can be useful to prefill the entire Buidler field.
ajnsn
ajnsnβ€’16mo ago
This is the default for the whole builder πŸ™‚
ins1d3r_
ins1d3r_OPβ€’16mo ago
@ajnsn Thanks, using the ->default() did exactly what I wanted.
Want results from more Discord servers?
Add your server