How to trigger a form save from another action?

Goal: What i am trying to achieve is when a user selects an item, if they hit the suffix 'edit' it will take them to that relationships edit page. Problem: When I click the edit option, it goes to the edit page, but it doesnt save that i selected that thing. Here is my select field
Select::make('video_id')
->relationship('video', 'title')
->searchable()
->allowHtml()
->required()
->getSearchResultsUsing(function (string $search) {
// some irrelevant code
})
->getOptionLabelUsing(function (int $value): string {
// some irrelevant code
})
->suffixAction(
Action::make('edit')
->icon('heroicon-m-pencil-square')
->action(function ($state, ?Model $record) {
// go to video edit page
// somehow trigger form save before navigating away
info("Edit video with id: $state");
})
),
Select::make('video_id')
->relationship('video', 'title')
->searchable()
->allowHtml()
->required()
->getSearchResultsUsing(function (string $search) {
// some irrelevant code
})
->getOptionLabelUsing(function (int $value): string {
// some irrelevant code
})
->suffixAction(
Action::make('edit')
->icon('heroicon-m-pencil-square')
->action(function ($state, ?Model $record) {
// go to video edit page
// somehow trigger form save before navigating away
info("Edit video with id: $state");
})
),
any help would be much appreciated!
3 Replies
OrdinaryDev
OrdinaryDevOP14mo ago
If the user selects a video, and then clicks the edit button, I want to trigger some sort of message if the form is in a dirty state saying they should save first or have a save and continue button or something.
No description
Patrick Boivin
Patrick Boivin14mo ago
Just a thought - can you instead open the Edit page in a new tab?
Ric Le Poidevin
Ric Le Poidevin9mo ago
@OrdinaryDev Did you find a solution to saving from the action? I have the same issue. Seems like it should be simple as I think a lot of people will want to save their data before running an action.
Want results from more Discord servers?
Add your server