Persist and save information from modal additional inputs

Hi, i'm using the admin panel and the table repeater and drop-in actions plugins by awcodes. I am a newbie to livewire, I'm working in my 'FormResource\Pages\EditForm', I need the information added in the form of DropInAction persist and when the user has finished adding fields and their additional options, press save to save all changes to all fields in the database. Also, how can i fill this modal inputs with the corresponding information?
TableRepeater::make('options')
->relationship('formFields')
->label('')
->disableLabel()
->cloneable()
->schema([

TextInput::make('name')
->required(),
//... more fields

//Button in tablerepeater showing additional inputs in modal to be added to each formField. Saving this additional data in database will be when user click save button in parent.
DropInAction::make('additional-options-field')
->execute(function (Closure $get, Closure $set) {
return Action::make('fillOptions')
->mountUsing(
//How can i fill the data in modal?
)
->action(function (array $data, $component, $livewire) use($get, $set): void {
//...
}
->form( function() use($get) {
return [
TextInput::make('options.minLength'),
TextInput::make('options.maxLength'),
TextInput::make('options.minValue'),
TextInput::make('options.maxValue'),
];
})
}),

]),
TableRepeater::make('options')
->relationship('formFields')
->label('')
->disableLabel()
->cloneable()
->schema([

TextInput::make('name')
->required(),
//... more fields

//Button in tablerepeater showing additional inputs in modal to be added to each formField. Saving this additional data in database will be when user click save button in parent.
DropInAction::make('additional-options-field')
->execute(function (Closure $get, Closure $set) {
return Action::make('fillOptions')
->mountUsing(
//How can i fill the data in modal?
)
->action(function (array $data, $component, $livewire) use($get, $set): void {
//...
}
->form( function() use($get) {
return [
TextInput::make('options.minLength'),
TextInput::make('options.maxLength'),
TextInput::make('options.minValue'),
TextInput::make('options.maxValue'),
];
})
}),

]),
php Is this possible something possible to do? maybe there is a better approach to do this? I hope i explain myself clearly, Thanks in advance.
3 Replies
Franco Miranda
Franco MirandaOP2y ago
Right now I've been trying this inside action:
->action(function (array $data, $component, $livewire) use($get, $set): void {
//get the values of form with $data
$options = $data['options'] ?? [];
//get all the sections in form, each section has multiple fields
$sectionsForm = $component->getLivewire()->data['sections'];

foreach ($sectionsForm as $section) {
foreach ($section['options'] as $field) {
if ($field['options'] == $data['id']) {
append $formFieldModel['options'] to $field['options']
$mergedOptions = array_merge($field['options'], $options['options']);
$field['options'] = $mergedOptions;

//This works inside this if
}
}
}
}

//But here is lost
->action(function (array $data, $component, $livewire) use($get, $set): void {
//get the values of form with $data
$options = $data['options'] ?? [];
//get all the sections in form, each section has multiple fields
$sectionsForm = $component->getLivewire()->data['sections'];

foreach ($sectionsForm as $section) {
foreach ($section['options'] as $field) {
if ($field['options'] == $data['id']) {
append $formFieldModel['options'] to $field['options']
$mergedOptions = array_merge($field['options'], $options['options']);
$field['options'] = $mergedOptions;

//This works inside this if
}
}
}
}

//But here is lost
LeandroFerreira
Did you try something like this?
->mountUsing(fn (ComponentContainer $form) => $form->fill([
'options' => ['minLength' => 1],
]))
->mountUsing(fn (ComponentContainer $form) => $form->fill([
'options' => ['minLength' => 1],
]))
https://filamentphp.com/docs/2.x/admin/pages/actions#filling-default-data
Filament
Actions - Pages - Admin Panel - Filament
The elegant TALL stack admin panel for Laravel artisans.
Franco Miranda
Franco MirandaOP2y ago
Thanks it worked and solves my fill issue.
Want results from more Discord servers?
Add your server