Add new frequency

add additional frequency to “Show every specific time until registration is complete”

1 Like

Hi @Nader_Bakhoum :wave:

The thing is that after the form is submitted, users usually close the popup. So, “Show every time until I close it” frequency should work for this case


Let me know if this explains things or if you have any questions left :slightly_smiling_face:

I tried that option but this setting doesn’t not enforce the user to register before he closes the form.

1 Like

Ah, got it! For this, you just need to disable the Close button on the Layout tab and keep using “Show every time until I close it” frequency:


This way, users will have to submit the form first, and only after that, they’ll be able to close it by clicking on OK button.

With the “Show every time until I close it” frequency, the popup won’t appear for users who submitted it.

Check it out and let me know if it worked for you :slightly_smiling_face:

I followed your settings and I turned on the backdrop.
I still want to get this popup to show on after every frequency time which I set it up for 20 sec for now.

1 Like

@Nader_Bakhoum, I’ve checked your website, and it looks like everything is working as you described now. The widget appears 20 seconds after the page loads, and when you reload the page, the popup appears again after 20 seconds.

Just to clarify - does everything work as you expected now? Or did you want the popup to appear 20 seconds after it’s submitted or closed, without needing to reload the page?

I want the popup to show up every 20 seconds until registration is complete without reloading the page.
Do you understand what I mean now?

1 Like

Got you, thanks!

I am not sure if it’s feasible, but I’ll discuss it with the devs and update you tomorrow :slightly_smiling_face:

I think it’s not that hard.
Create a routine to execute a task every specific time until the task is complete

1 Like

Hi again, @Nader_Bakhoum :wave:

I’ve talked to the devs, and they’ve confirmed that it’s possible to implement this feature.

To make it work, you need to enable the Close option ( Close button or Close popup on overlay click in the Backdrop settings) and this code to the Custom JS section on the Settings tab:

widget.form.on('submit', () => {
  window.localStorage.setItem(KEY, 'true');
});

const WIDGET_ID = '095f6e1b-ca8c-49c9-9e93-bfbc4a77f7fe';
const DELAY = 20; // In seconds
let installTimeout = null;

const KEY = 'elfsight-form-submitted';

function stopInterval() {
  if (!installTimeout) {
    return;
  }

  clearInterval(installTimeout);
  installTimeout = null;
}

function startInterval(target, observer) {
  installTimeout = setInterval(() => {
    const isFormSubmitted = window.localStorage.getItem(KEY) === 'true';

    if (isFormSubmitted) {
      stopInterval();
      observer.disconnect();

      return;
    }

    const button = target.querySelector(
      '[class*="ButtonBase__ButtonContainer-sc"]'
    );
    button?.click();
  }, DELAY * 1000);
}

function handleMutations(mutations, observer) {
  const targetNode = mutations.find(
    ({ target }) =>
      target.id === '__EAAPS_PORTAL' && target.className.includes(WIDGET_ID)
  )?.target;

  if (!targetNode) return;

  const isPaneOpen = targetNode.querySelector(
    '[class*="Pane__PaneContent-sc"]'
  );

  if (isPaneOpen) {
    stopInterval();

    return;
  }
  if (!installTimeout) {
    startInterval(targetNode, observer);
  }
}

const mutationObserver = new MutationObserver(handleMutations);
mutationObserver.observe(document.body, { childList: true, subtree: true });

Try it out and let me know how it worked :slightly_smiling_face:

Hello,

it works now the way I expected except once the user complete the registration and go to another page, the form shows up again.

can you modify the code so the form does not show up again to the same user on other pages after the registration is complete?

1 Like

I am so sorry about that!

We’ll double-check it with the devs, and I’ll update you tomorrow!

Hello, I do not know what happened but the popup stopped showing up after clicking on the backdrop again and it does not show up again