I have been trying this many hours and couldn't get it working. I have an element with d3 that is draggable using drag behavior, and I want to add a dblclick event, so it performs an action when it is double clicked. I couldn't get the dblclick event to be reached. I have studied many ways of trying to stop propagation from within the drag, and changing the order of the declaration of events, with no success so far. My code is like:
switch = box.append('rect')
.data([{x: point.x, y: point.y}])
.attr('transform', function (d) { return 'translate(' + d.x + ',' + d.y + ')'; })
.attr('height', 8)
.attr('width', 8)
.attr('stroke', color)
.attr('fill', color)
.on('dblclick', function () {
d3.event.stopPropagation();
alert('Hello'); // Doesn't enter
}, true).call(d3.behavior.drag().on('dragstart', function () {
d3.event.sourceEvent.stopPropagation();
}).on('drag', function (d) {
d.x += d3.event.dx;
d.y += d3.event.dy;
d3.select(this).attr('transform', 'translate(' + d.x + ',' + d.y + ')');
}).on('dragend', function (d) {
}));
Note the "true" after the on('dblclick', ..., true) declaration. I was trying to prevent the propagation.
Any help is appreciated.