-
Hello! I'd like to use a custom dialog for confirmation. In this case the
This works only for the built-in window.confirm - you can't create a custom function which returns after button was clicked. So, what is the proper way to implement a custom confirmation dialog with Naja? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi, I'm afraid this is the way it is with the DOM's event system: it's synchronous and it doesn't play well with any kind of asynchronous workflow. So yes, you need to call naja.uiHandler.addEventListener('interaction', (event) => {
if (event.detail.element.hasAttribute('data-confirm') && !event.detail.options.bypassConfirmation) {
event.preventDefault();
customAsyncConfirmation(event.detail.element.getAttribute('data-confirm'))
.then(() => {
naja.uiHandler.clickElement(event.detail.element, {bypassConfirmation: true});
});
}
}); |
Beta Was this translation helpful? Give feedback.
Hi, I'm afraid this is the way it is with the DOM's event system: it's synchronous and it doesn't play well with any kind of asynchronous workflow. So yes, you need to call
preventDefault()
synchronously and then replay the interaction. A quick-n-dirty solution could look something like this: