Automatic modal closure after button pressed on it

Just remove the <> and u should able to see

Can you try this one

<script>
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>

To be inserted in the footer code of the page settings (in the page where the modal is open when you click on a list item). When closing the modal with the close button, it should reload the page.

Let me try and get back to you. Thank you very muchđŸ™đŸ»

Good morning, here is your annoying reminder that setting a single timeout is going to create random hard-to-diagnose problems for your users who might be on a slower computer or just having intermittent network connectivity problems.

Instead, it’s better to use setInterval() with a test to see if the condition you’re waiting for has in fact occurred, and then clearInterval() to cancel the timer.

“Damn, he saw it!”. I will update this :sweat_smile:

2 Likes

Here it is @dcoletta

<script>
window.addEventListener('load', function() {
  var intervalSet = setInterval(function() {
    var e = document.getElementsByClassName("sw-modal-close")[0];
    if (e) {
      e.setAttribute('onclick', "MicroModal.close('sw-modal');  location.reload();");
      clearInterval(intervalSet);
    }
  }, 100);
});
</script>
5 Likes

@matthieu_chateau this is awesome, thank you for receiving my annoying feedback so gracefully!

3 Likes

Dear Masters,

I have tried, but there is not effect at all, just like Matthiew said, I put it on the list page, where the modal would be triggered. Here enclose the pict showing how I put it on the customs code:

Also, I enclose a clipping of how’s the response on the page.

Hope you can give me some clues how to make your great code activated! I think this function should help a lot of other Softr users. :smile:

I have just been aware that after pressing the X button on the upper right hand corner, after closure of the modal page, the master page refresh automatically. Therefore, the code seems to be effective in a way, but not totally.

Probably, there is something missing to really kick off the first part of the code.

Mmmmm this is what does the code = on click on X it reloads the parent page, only this :thinking:. Not on form submit

1 Like

@Viktoria Could you please kindly check with your technical team and ask for their advice, how the code should be adjusted in order to be effective with the modal page. I think this small enhancement could help a lot of users to create a better customer journey. Appreciate your kind assistance as usual :pray:

Just a quick verification: all the blocks (specifically the list block) are rightly updated?

If they are rightly updated, could we check the page? (A link to the live version would be the best)

Hi @twmeric :wave:
As Matthieu mentioned, would you mind sharing the link to the List block page of Published app, so I could review the custom code with the tech team?

Hi @Viktoria & @matthieu_chateau , here it comes with the real link that you can test and play: Update Link

The after closure refresh is performing just like what I want it to be, it refreshes and goes back to the particular position of the page so user don’t need to scroll.

Therefore, what I miss is the closure of the modal page, where there should be two things happen upon pressing it:

  1. send out data to airtable (as it always does)
  2. close itself 2 seconds after showing the green wordings which indicates a successful update

I wonder if the highlighted part need to be addressed with some codes.

Hope the above details would help working out the viable code which should enhance user experience a lot - a few lines of code can make a huge difference. Nice weekend!

Does this work with the side-modal? I have put this in my main-page footer. When I close the modal, it doesn’t refresh the page though.

Here’s what I’ve got in my footer of the main page:

Hi @twmeric,

Here the code you need to insert in the page that will be used as a popup and where the form is (so not to be inserted in the parent page)

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

Just change form1 by the name of your form

@flavi Just to be sure, you want the page to refresh after clicking on this X button (the close button) or after a form submission? If after a form submission: just do exactly like I wrote above.
If it’s on close modal action (so with the X button), I dont have any solution and I won’t do it (I realize there is no sense to have such action)

1 Like

Hi Matthieu, highly appreciate and I think this code should be well shared with other softr user! :pray: Thanks for your great work again, nice weekend!

If this code is inserted in the footer of the sign-in page and the site sign in page is set to open in modal, will this automatically close the sign in modal and return the user to whichever page they were last on after signing in?

1 Like

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