Use pat-inject on a pat-plone-modal z3c.form success

I have the following pat-plone-modal link :

<a href="${context/absolute_url}/@@my-form" class="pat-plone-modal">Open my form in modal</a>

where @@my-form is a z3c.form.

When the form is submitted with validation errors, the response is displayed in modal with error. Great !

What I'd like is for the response to be injected (with pat-inject) into another part of the page when the form is successfully submitted, rather than reloading the page.

I saw in the documentation that I can set option reloadWindowOnClose to false to avoid reloading the page.

<a href="${context/absolute_url}/@@my-form" class="pat-plone-modal" data-pat-plone-modal='{"actionOptions":{"reloadWindowOnClose": false}}'>Open my form in modal</a>

How do I get the form succesfull response to replace the #a-section-in-my-page section of my page ?

You could try to use actionOptions.onSuccess which calls a globally registered script with the parameters self, response, state, xhr, form

just an draft JS:

window.my_success_factory = (pattern, response, state, xhr, form) => {
// do something with the response
}

and in the markupp

<a data-pat-plone-modal='{"actionOptions":{"onSuccess": "my_success_factory"}}'>link</a>
</body>

see more info in the pattern source code: mockup/src/pat/modal/modal.js at master · plone/mockup · GitHub

Note: as you've already said, this has to be in combination with actionOptions.reloadWindowOnClose = false