addaction - refresh repeater

If I use ->addaction to customise the addition of a repeater, how do I make it so that repeater refreshes with the latest data. At the moment, the data is going into the database, but I have to close the form down and re-open to see the new entry.
3 Replies
LeandroFerreira
are you using a relationship? Could you share the code that you are using?
Matthew
MatthewOP2d ago
Yes I am using a relationship, here is the code excerpt:
Repeater::make('notes')
->live()
->relationship('notes')
->addable()
->schema([

Placeholder::make('rfn_text_content')
->content(fn ($record) => $record ? $record->getContent() : '')
->label(fn ($record) => $record ? $record->getHeading() : ''),


Placeholder::make('rfn_text_by')
->content('')
->label(fn ($record) => $record ? $record->getAuthorAndDate() : ''),

]),
])
->addActionLabel('Add New Note')

->addAction(function (Action $action) {

$action
->icon('heroicon-m-plus-circle')
->color('primary')
->requiresConfirmation()
->form([
FormField::longDescription('newNote')
->label('Note info')
..
Radio::make('noteReminder')
->label('Set Reminder')
..
FormField::futureDate('noteActionDate')
->label('Reminder Date')
..
])
->action(function ($record, $data) {

$record->notes()->create([
'rfn_text' => Arr::get($data, 'newNote'),
'rfn_alert_date' => Arr::get($data, 'noteActionDate', null),
'rfn_uc_id' => getClientUser()->getId(),

]);

});
}),
Repeater::make('notes')
->live()
->relationship('notes')
->addable()
->schema([

Placeholder::make('rfn_text_content')
->content(fn ($record) => $record ? $record->getContent() : '')
->label(fn ($record) => $record ? $record->getHeading() : ''),


Placeholder::make('rfn_text_by')
->content('')
->label(fn ($record) => $record ? $record->getAuthorAndDate() : ''),

]),
])
->addActionLabel('Add New Note')

->addAction(function (Action $action) {

$action
->icon('heroicon-m-plus-circle')
->color('primary')
->requiresConfirmation()
->form([
FormField::longDescription('newNote')
->label('Note info')
..
Radio::make('noteReminder')
->label('Set Reminder')
..
FormField::futureDate('noteActionDate')
->label('Reminder Date')
..
])
->action(function ($record, $data) {

$record->notes()->create([
'rfn_text' => Arr::get($data, 'newNote'),
'rfn_alert_date' => Arr::get($data, 'noteActionDate', null),
'rfn_uc_id' => getClientUser()->getId(),

]);

});
}),
Taken out chunks of irrelevance. My addAction is adding the database record without issue. I suppose I could just add the data to the form as well ? (not sure exactly how). Just feels like there is likely to be a command somewhere to refresh the form. I'm using a Modal, rather than the Edit\View Page. Update...I've decided I'm trying to hack too much here. What I really want is a table within an infolist or a form, rather than trying to use a repeater. I'm not that confident with livewire, so not too keen on going into custom livewire pages\modals. However, I have worked out that I can add a ViewField to a form, and then call a table widget from the corresponding blade. This gives me more function than before, so happy with that for now.
LeandroFerreira
Maybe this can help you https://discord.com/channels/883083792112300104/1313505581436244019/1313797927226966036 try to inject $component and use this after creating the record
$component->clearCachedExistingRecords();
$component->fillFromRelationship();
$component->clearCachedExistingRecords();
$component->fillFromRelationship();

Did you find this page helpful?