Refreshing a block API call manually

I haven’t been able to find any exampled or information on this topic. Since one of the last big updated , any edits will automatically refresh the block and call the new records, which has been great. However I would now like to be able to call this manually either by button or external form submission, has anyone had any luck implementing something similar?

Hi, you can also use the custom code to automate the page refresh with time intervals comfortable for your use case. You will find the custom code here: Auto refresh displayed block data - #5 by Virginie

@Marine.Hovhannisyan You should be able to reload only the block :nerd_face: => Refresh / Reload data in a List Block - #5 by artur

Though some blocks may not be ready yet for this new function (specifically the table block).

On form submit the code would look like this. form1 and list1 to be changed with your block IDs -
Code to be inserted in the custom code footer of the page.

<script>
  document.addEventListener('DOMContentLoaded', () => {
    window.addEventListener('submit-form-success-form1', () => {
      window.dispatchEvent(new CustomEvent('reload-block-list1'));
    });
  });
</script>

Yep, @matthieu_chateau, agree with you :pray: As I was not 100% sure that it would work with all the blocks, I offered a safer workaround.

Right!

For a page reload this would be =>

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

Thanks @matthieu_chateau this is exactly what I need, only for it to work on tables. But it’s good to have in the mean time for other projects.