Emit Event from Resource to Relation Manager

I have an EditResource page with a relation manager. I want to put a button in getActions so that there is an option to create a new relation at the top of the page (instead of being forced to scroll down). I want the action from the resource getActions to trigger the create action on the relation manager. Is this possible?
2 Replies
Patrick Boivin
Patrick Boivin16mo ago
This is a bit hacky, but something you can experiment with:
// At the top of the page
Action::make('triggerCreate')
->extraAttributes([
'x-on:click' => new HtmlString(
"document.querySelector('#relation-manager-create').click()"
)
]),

// In the relation manager
CreateAction::make()
->extraAttributes(['id' => 'relation-manager-create']),
// At the top of the page
Action::make('triggerCreate')
->extraAttributes([
'x-on:click' => new HtmlString(
"document.querySelector('#relation-manager-create').click()"
)
]),

// In the relation manager
CreateAction::make()
->extraAttributes(['id' => 'relation-manager-create']),
Trigger the action at the bottom in JS, from the button at the top.
bwurtz999
bwurtz999OP16mo ago
This works perfectly! Thank you!
Want results from more Discord servers?
Add your server