Refresh after modal close?

Is it possible to force the parent page to refresh whenever a modal is closed?

1 Like

and retin what was in the search

Doesn’t involve search. List details page with buttons that open modals containing forms for various actions. Would like the main page with the details data to refresh whenever the modal is closed. As it is now, if a form is used to launch an automation that updates something on the page where the modal was launched, the user doesn’t see that it’s been updated when closing the modal because the page doesn’t refresh.

Add this to Code inside footer of the parent page, not the modal page.

It adds refresh after you click the close modal button (assumes the “Do nothing” action is set for the modal)

window.addEventListener('load', function() {
    setTimeout(function() {
        var e = document.getElementsByClassName("sw-modal-close")[0];
        e.setAttribute('onclick', "MicroModal.close('sw-modal');  location.reload();");
    }, 1600);
});
</script>

PS Some apps need a pause before reload, perhaps to wait for an Airtable automation to complete:
e.setAttribute('onclick', "MicroModal.close('sw-modal'); setTimeout(location.reload.bind(location), 1600);");

1 Like

@cooper What do you mean by “Do nothing” action? I don’t see any modal options other than size.

I meant the do nothing option on Form submit within modal. Just laying out my use case since Softr tends to vary quite a bit, impacting code example. But may be of no consequence in this case!

Hi @cooper - so this doesn’t seem to work for modals now. Do you know if there have been any updates to reload if a modal is closed? Thanks!

@Jakob @rebeccajane It’s definitely not “No Code,” but you could probably use the sessionStorage mechanism of the Web Storage API combined with polling or a click event to refresh the parent page.

Hi Rebecca,
What type of modal are you talking about exactly? Is it a modal displayed in the center of the screen? A lateral modal? A modal of an action button (add/delete/update modals)?

The code still works for the modals displayed in the center of the screen