2 "save" actions on CreateResource with "mutateFormDataBeforeCreate"
Hi All,
I'm aware that actions can be added to a Resource. I would like to add an additional "Save" button on the CreateResource page. My goal is to mutate one parameter (e.g., $data['status'] = InternalStatus::CONCEPT) only when this new button is pressed.
Does anyone have any ideas on how to achieve this?
Thanks in advance!
Solution:Jump to solution
Here is the solution.
Create a Formfield, hide the label and add
hidden
as extraAttributes
```php...8 Replies
Implement
getFormActions()
on the CreatePage. See the original implementation for referenceI have that implemented,
But don't know how to mutate the data for the "getCreateConceptFormAction"
That's why I said "see the original implementation". It doesn't have a
->action()
method:
This is the original code:
And this calls the create()
method on the CreateRecord class.So i need to duplicate the create function to only change 1 attribute that needs to be changed?
Just like below where i added the
$data['status'] = InternalProjectStatus::CONCEPT->value;
Isent there a better way to do this?
How about this:
Damn, did not think about that!
Thanks, that will do the trick!
Solution
Here is the solution.
Create a Formfield, hide the label and add
hidden
as extraAttributes
For the action, set submit to null
and update the $livewire->data['status']
in action and than create the record.
This will set status to Concept
in my case.
If there is another way i would love to see it.
Because this works, but dont think this is the best way of doing this.Thanks for sharing.