Regarding the single-click event when double-clicking in "eventHandlers"

I’m trying to handle single-click and double-click events for an element using “eventHandlers”. However, when I double-click, the single-click event is triggered twice. Is there a way to prevent the single-click event from triggering when double-clicking?

Hello,

There is no built-in option to prevent the onclick handler when a double-click occurs. However, you can achieve the desired behavior by delaying the single-click action with a short timeout and cancelling it in the ondblclick handler:

let clickTimer = null;
const clickDelay = 250;

const vault = new dhx.Vault("vault", {
    ...
    eventHandlers: {
        onclick: {
            class_name: (_, id) => {
                clearTimeout(clickTimer);

                clickTimer = setTimeout(() => {
                    showMessage(`Single click: ${id}`);
                    clickTimer = null;
                }, clickDelay);
            }
        },

        ondblclick: {
            class_name: (_, id) => {
                clearTimeout(clickTimer);
                clickTimer = null;

                showMessage(`Double click: ${id}`);
            }
        }
    }
});

Example:

1 Like

@Maksim_Lakatkou

Thank you for replay and sample.

1 Like