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:Jump to solution
You can use
default()
- just build your desired array structure there, e.g.
`->default([
[
'type' => 'text',...5 Replies
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#L127Solution
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.I don't think this will work per-block. But it can be useful to prefill the entire Buidler field.
This is the default for the whole builder π
@ajnsn Thanks, using the ->default() did exactly what I wanted.