Automatic modal closure after button pressed on it

Yes, it work for me, but u need to manually close the confirm page, if u have.

In order to do this, here is the code:

What does it do? It listens if the form submit is a success or not. If there is a success, It asks the browser to go back 1 page.

Note that I don’t know if the sign in block has the same kind of event listeners as ‘submit-form-success’ but you can give it a try.

<script>
document.addEventListener('DOMContentLoaded', () => {
  window.addEventListener('submit-form-success-form1', () => {
    window.parent.history.back();
  });
});
</script>

If you need to go back two pages :point_down:


<script>
document.addEventListener('DOMContentLoaded', () => {
  window.addEventListener('submit-form-success-form1', () => {
    window.parent.history.go(-2);
  });
});
</script>

Update: sign in and sign up event listeners will be added by Softr within the next 2 weeks. I will update the code accordingly

2 Likes

Hello Matthieu,
can I open form from list details into side modal, then after from submission to close the modal and update the parent page automatically? if yes, how to do?

Hi Tawfeeq,
It works exactly the same as: Automatic modal closure after button pressed on it - #20 by matthieu_chateau
With this code you don’t have to worry about the type of modal to close, as all is made by the page reload (and as a page reload always closes any modal => 2 actions in 1)

1 Like

Firstly thank you so much Matthieu for all you work in the forum - unreal!
In relation to

<script>
document.addEventListener('DOMContentLoaded', () => {
  window.addEventListener('submit-form-success-form1', () => {
    window.parent.location.reload();
  });
});
</script>

Instead of form I wanted to use a list which in turn updated a record with Softr’s new action button.
I thought it would be a case of changing ‘submit-form-success-form1’ -but how wrong I was.

Are you able to give any guidance at all?

Many Thanks in advance!

Hi!

Yes I can,

Here are the event listeners given by Artur for the new action buttons= Action Buttons - Update Records event listeners

So the code for you would be

<script>
document.addEventListener('DOMContentLoaded', () => {
  window.addEventListener('update-record-success-list1', () => {
    window.parent.location.reload();
  });
});
</script>

Just change list1 by the name of your list. The code needs to be inserted in the footer code of the page settings where your list is.

PS: I couldn’t see the script you wanted to show me (But I did it for you, don’t worry, now it’s visible). To show scripts in a post, be careful to use this option in the text editor, when writing : </>

Tell me if it worked!

Note also that updating a record with the update action button will update the list automatically without needing this code. But maybe you want something in the parent page to be updated according to the update of the list in the child page? (Hopefully I can be understood :sweat_smile:)

Thank you so much for your speedy reply @matthieu_chateau

It worked like a dream! I am hoping other users will get the same benefits!
Cant thank you enough.

1 Like

One question is there a way we could add a small buffer to the refresh rate like 2 seconds as its refreshing before the Airtable has finished its automatons.

Yes,

Here it is:

<script>
document.addEventListener('DOMContentLoaded', () => {
  window.addEventListener('update-record-success-list1', () => {
    setTimeout(() => {
      window.parent.location.reload();
    }, 2000);
  });
});
</script>

Or

<script>
document.addEventListener('DOMContentLoaded', () => {
  window.addEventListener('update-record-success-list1', () => {
    const intervalId = setInterval(() => {
      clearInterval(intervalId);
      window.parent.location.reload();
    }, 2000);
  });
});
</script>

You can vary the delay by changing ‘2000’ (milliseconds)

Thank you so much - unfortunately this is now stopping the closure of the box and the refresh of the parent page. Would there be anything in the parent page I would need to add? Thank you once again.

Nothing to do in the parent page.

Maybe you could try 3000?

Or use the second script I gave?

I tried on my end with a similar use case, no problem even with 1500 (the code must be in the page where the modal leads, child page. As you update a list which is in a modal?)

3000 - was the magic number! Honestly that’s wonderful stuff - really grateful for you support. Been banging my head against this today. Super happy!

1 Like

Hi. Will this work with the new delete action as well?

I don’t remember if the delete event listeners are added but you can try ‘delete-record-success-listX’. If not working, wait a week or so and it should be added by then

@matthieu_chateau do you know if we have the delete record event already? I tried but it is not firing…

Hi Pedro,

I think that for delete record the event listener is still submit-form-success-listX

1 Like

Thanks for answering! Now it worked with 'delete-record-success-listx'

2 Likes

The delay reload isn’t working for the add record action though. Any ideas?

Hi Rebecca,

The event listener for add record should be submit-form-success-listxx for now, from the latest news I know (though I have to test it - UPDATE = It is indeed submit-form-success-listxx listxx being the id/name of your block)

If you have issues to build the correct script, I can do it for you by replying here. If so, would you mind giving me the name of the block where the add record button is?
Also this block is inside a modal? You want to reload the parent page or the child page? (child page being the modal page)

Hi @matthieu_chateau thanks for your reply and offer to help! So I do have it reloading once the add record is submitted. The block and add record are in the same block and on the same page.

window.addEventListener('submit-form-success-requests-list', (e) => {
	console.log('add record success', e.detail);

    sessionStorage.setItem('scrollPosition', window.scrollY || window.pageYOffset);

    // Trigger the page reload
    window.location.reload();
});

However it’s not allowing for a delay in load. I tried this and it didn’t pause on reload

window.onload = function() {
    if (sessionStorage.getItem('scrollPosition') !== null)
        window.scrollTo(0, sessionStorage.getItem('scrollPosition'));
}

window.addEventListener('submit-form-success-requests-list', (e) => {
	console.log('add record success', e.detail);

    sessionStorage.setItem('scrollPosition', window.scrollY || window.pageYOffset);

    // Trigger the page reload
        setTimeout(() => {
        window.location.reload();
    }, 15000);
});

Thanks for your help!