F
Filament9mo ago
lmtc

getting the builder component id into a hidden field

I'm trying to add the same id I'm storing into a hidden field so I can pull in the values later, but can't seem to get it to populate?
BuilderComponent::make('fields')
->label('')
->collapsible()
->cloneable()
->live()
->reorderableWithButtons()
->addActionLabel('Add field')
->extraItemActions([
Action::make('add_styling')
->icon('heroicon-m-paint-brush')
->form([
Section::make('example')
->schema([TextInput::make('label')]),
])
->action(function (
array $data,
array $arguments,
FormsModel $record,
BuilderComponent $component
): void {
$item_id = $arguments['item'];

$record = new FormStyling();
$record->label = $data['label'];
$record->field_id = $item_id;
$record->save();

})
])
->blocks([
BuilderComponent\Block::make('text_field')
->label('Text Field')
->schema([
Grid::make(2)
->schema([
Hidden::make('form_styling_id')
->default(function (array $arguments, BuilderComponent $component) {
return $arguments['item'] ?? null;
}),
BuilderComponent::make('fields')
->label('')
->collapsible()
->cloneable()
->live()
->reorderableWithButtons()
->addActionLabel('Add field')
->extraItemActions([
Action::make('add_styling')
->icon('heroicon-m-paint-brush')
->form([
Section::make('example')
->schema([TextInput::make('label')]),
])
->action(function (
array $data,
array $arguments,
FormsModel $record,
BuilderComponent $component
): void {
$item_id = $arguments['item'];

$record = new FormStyling();
$record->label = $data['label'];
$record->field_id = $item_id;
$record->save();

})
])
->blocks([
BuilderComponent\Block::make('text_field')
->label('Text Field')
->schema([
Grid::make(2)
->schema([
Hidden::make('form_styling_id')
->default(function (array $arguments, BuilderComponent $component) {
return $arguments['item'] ?? null;
}),
Solution:
Updating with solution: ``` ->action(function ( array $data, array $arguments,...
Jump to solution
2 Replies
Solution
lmtc
lmtc8mo ago
Updating with solution:
->action(function (
array $data,
array $arguments,
FormsModel $record,
BuilderComponent $component,
): void {
$item_data = $component->getItemState($arguments['item']);
$item_id = $item_data['form_styling_id'];
$form_data = $data;

$existing_record = FormStyling::where('field_id',
$item_id)
->first();

if ($existing_record) {
$existing_record->label = $data['label'];
$existing_record->save();
} else {
$record = new FormStyling();
$record->label = $form_data['label'];
$record->field_id = $item_id;
$record->save();
}
})
->action(function (
array $data,
array $arguments,
FormsModel $record,
BuilderComponent $component,
): void {
$item_data = $component->getItemState($arguments['item']);
$item_id = $item_data['form_styling_id'];
$form_data = $data;

$existing_record = FormStyling::where('field_id',
$item_id)
->first();

if ($existing_record) {
$existing_record->label = $data['label'];
$existing_record->save();
} else {
$record = new FormStyling();
$record->label = $form_data['label'];
$record->field_id = $item_id;
$record->save();
}
})
lmtc
lmtcOP8mo ago
Hidden::make('form_styling_id')
->default(function () {
return Str::uuid()
->toString();
}),
Hidden::make('form_styling_id')
->default(function () {
return Str::uuid()
->toString();
}),
Want results from more Discord servers?
Add your server