#Refresh page data from resource form action

20 messages · Page 1 of 1 (latest)

void smelt
void smelt
#

Ah ha, thanks! I tried $page. Is there a list of everything that can be passed to those closures somewhere?

#

That works, but refreshFormData doesn't seem to be doing anything. I'm trying to refresh a relationship (displayed as a repeater). Any ideas?

void smelt
#

Perfect thanks

lethal chasm
void smelt
#

Sure. Just for context, I want to override the repeaters add action to use a modal that prompts for data and then actually creates the record. It all works perfectly, except I need the repeater to update with the newly added item.

Forms\Components\Repeater::make('chapters')
    ->relationship()
    ->label('Lessons')
    ->itemLabel(fn (array $state): ?string => $state['title'] ?? null)
    ->addActionAlignment(Alignment::Start)
    ->addAction(fn ($action) => $action
        ->form([
            Forms\Components\TextInput::make('title')
                ->required(),
        ])
        ->action(function (Page $livewire, Course $record, array $data) {
            Chapter::create([
                ...$data,
                'course_id' => $record->id,
            ]);
            $livewire->refreshFormData(['chapters']);
        }))
lethal chasm
void smelt
#

That works, thanks! But, when you then hit save on the form it attempts to save the chapter again, which fails with a null title column error, and that somehow deletes the row that was previously added... do I need to tell it that item already exists somehow?

lethal chasm
void smelt
#

Yeah I did try that, but I need the drag and drop re-ordering feature. May have to cook up a custom field.

lethal chasm
void smelt
#

Ah OK, thanks I'll check that out.

#

It does get even more complicated, because each chapter then has a list of lessons, and ideally I want to end up with a single view where you can add/edit/delete/reorder chapters and lessons 😂

#

In theory repeater works great for this, I've got the add/edit/delete/reorder working great, it's just syncing the data after the actions that's the issue.

void smelt
void smelt
#

And it works perfectly on the nested repeaters as well.