Replace modal actions with 'save' and 'save & close'?

this is my first attempt and simply working on have them both
->modalSubmitAction(false)
->extraModalFooterActions(fn (Action $action): array => [
$action->makeModalAction('save')
->label('Save')
->action(function ($record, $data) {
ray($record)->orange()->label('save record');

return $this->saveInquiry($record, $data);
})
->color('primary')
->button(),
$action->makeModalAction('save_close')
->label('Save & Close')
->action(function ($record, $data) {
ray($record)->orange()->label('save & close record');

return $this->saveInquiry($record, $data);
})
->color('primary')
->button(),
])
->modalSubmitAction(false)
->extraModalFooterActions(fn (Action $action): array => [
$action->makeModalAction('save')
->label('Save')
->action(function ($record, $data) {
ray($record)->orange()->label('save record');

return $this->saveInquiry($record, $data);
})
->color('primary')
->button(),
$action->makeModalAction('save_close')
->label('Save & Close')
->action(function ($record, $data) {
ray($record)->orange()->label('save & close record');

return $this->saveInquiry($record, $data);
})
->color('primary')
->button(),
])
, though as i type this, i should probably use the existing submit and relabel it, though i do want to use the above order. My problem with the regular 'save' action that im trying to do above is that its not actually saving it and if i put a `ray() on the action(), it doesnt appear to run. My goal is to have the primary 'save' action to not close the modal and only have it do that if selecting the 'save and close' action
3 Replies
Mark Chaney
Mark ChaneyOP16mo ago
am i overcomplicating this or is there a simpler method to simply having a regular submit and a save, but keep the modal open button?
Kenneth Sese
Kenneth Sese16mo ago
Have you tried using halt() to prevent the modal from closing?
Mark Chaney
Mark ChaneyOP16mo ago
I thought that was more for stopping the data from being submitted, but that could work. Ive honest never used it, so i guess i should look into it @archilex
->modalSubmitAction(false)
->extraModalFooterActions(fn (Action $action): array => [
$action->makeModalSubmitAction('save', arguments: ['halt' => true])
->label('Save')
->color('primary'),
$action->makeModalSubmitAction('save_close', arguments: ['halt' => false])
->label('Save & Close')
->color('primary'),
])
->action(function ($action, $record, $data, $arguments) {
$this->saveInquiry($record, $data);

if ($arguments['halt'] === true) {
$action->halt();
}

return true;
})
->modalSubmitAction(false)
->extraModalFooterActions(fn (Action $action): array => [
$action->makeModalSubmitAction('save', arguments: ['halt' => true])
->label('Save')
->color('primary'),
$action->makeModalSubmitAction('save_close', arguments: ['halt' => false])
->label('Save & Close')
->color('primary'),
])
->action(function ($action, $record, $data, $arguments) {
$this->saveInquiry($record, $data);

if ($arguments['halt'] === true) {
$action->halt();
}

return true;
})
thanks for the idea of halt() now i just have to figure out how to rerender the form after i do the halt. This way it shows the updated notes and the note field is empty again (in my saveInquiry() method, i unset the note field after i save it somewhere else) i swear i saw something about refreshing a modal record from an action, but cant track it down again @Hugh Messenger now with all your nested modal work, im sure you have had to update the record in a modal. Basically in
if ($arguments['halt'] === true) {
$action->halt();
}
if ($arguments['halt'] === true) {
$action->halt();
}
before the halt, i would need to somehow refill the modals form with $record->refresh() i would think. tried a few things with $livewire and even doing an emit $refresh, but no dice and i dont think that targets the modal anyway
Want results from more Discord servers?
Add your server