Get path for builder/block input

I have a builder on a page and I can therefore generate several blocks which each contain an input text with the name XXX. But once the blocks are generated, all the input elements have the same name (XXX). I'm looking for ways to target them one by one, for example to add content.
3 Replies
beuzathor
beuzathorOP11mo ago
To simplify let's admit that I have a builder like this on my page :
Forms\Components\Builder\Block::make('richtext')
->label(function (?array $state): string {
if ($state === null) {
return 'Heading';
}
return $state['name'] ?? 'Untitled heading';
})
->schema([
TextInput::make('name')->disabled(),
TextInput::make('Description')->disabled(),
//// RichEditor::make('content')->required()->id('good'),
RichEditor::make('name'),

// ...
]),
Forms\Components\Builder\Block::make('richtext')
->label(function (?array $state): string {
if ($state === null) {
return 'Heading';
}
return $state['name'] ?? 'Untitled heading';
})
->schema([
TextInput::make('name')->disabled(),
TextInput::make('Description')->disabled(),
//// RichEditor::make('content')->required()->id('good'),
RichEditor::make('name'),

// ...
]),
Now i add 2 same block on my page so i have richtext 1 et richtext 2 like in the img Now I have a function that generates text and I would like to place this text inside one of these fields. Usually it would be in "content". This fonction is called via an action like that
Forms\Components\Actions::make([
Forms\Components\Actions\Action::make('word_count')
->action(function ( Set $set, $state) {
$dispatchController = new GenerateBlogFormController();
$response = $dispatchController->generate($state);


$title = $response->getData(true)['title'];
/// dd($title);
$set('name-field', $title);
})
]),
Forms\Components\Actions::make([
Forms\Components\Actions\Action::make('word_count')
->action(function ( Set $set, $state) {
$dispatchController = new GenerateBlogFormController();
$response = $dispatchController->generate($state);


$title = $response->getData(true)['title'];
/// dd($title);
$set('name-field', $title);
})
]),
My probleme is to the last line. I don't know how to target the input of CustomRichEditor::make('name') because there is 2 on the same page (can have many more).
No description
LeandroFerreira
LeandroFerreira11mo ago
GitHub
Get path for builder/block input · filamentphp filament · Discussio...
I have a builder on a page and I can therefore generate several blocks which each contain an input text with the name XXX. But once the blocks are generated, all the input elements have the same na...
beuzathor
beuzathorOP11mo ago
thanks you i reply on GH
Want results from more Discord servers?
Add your server