0

I am using vis-timeline 7.4.7.

There is a feature, the website says:

When the Timeline is configured to be editable (both options selectable and editable are true), the user can: ... Create a new range item by dragging on an empty space with the ctrl key down...

I need to use the options.add=true, also the editable and the selectable, because of the other features I am using.

My question is: is there a way to disable the "add new item with ctrl/meta + click-and-drag" feature?

I found that it is handled by Input.domHandler -> ... -> recognize -> ... -> propagatedHandler -> _onDragStart -> _onDragStartAddItem, but I could not find a way to set an option to disable this.

Note: That would be a great workaround to hide the new blue element (with a build-in text says "new item"), but the new element does not have any special class or anything I could target with CSS. (The item will not stay alive, as I can catch it with the onAdd function, but it runs only AFTER the user released the mouse button)

My current workaround is that I add my own class to all the elements I create, so I can tartet the new element with :not(). Well... not the best solution :(

Note2: it is happening not only with ctrlKey, but also with metaKey

  • I am one this exact same problem right now. on the old vis repo: https://github.com/almende/vis/issues/3912 – Fanna1119 Dec 09 '21 at 15:45

1 Answers1

0

How i got around it is like this.

A bit hacky. On the onAdd event listener I did the following.


function isUUID(uuid) {
    var regex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
    return regex.test(uuid);
}

    onAdd: (item, callback) => {
        if (item.content == 'new item' && isUUID(item.id) ) {
            callback(null)
        } else {
            //emits('onAdd', item);
            callback(item);
        }


Fanna1119
  • 1,878
  • 4
  • 24
  • 30
  • Well, thank you, but unfortunately onAdd is called after the item is placed, so with your solution, the user is still able to visually create a new element with the text "new item". My aim to disable the ability to create new items ctrl+click. – György Szy Dec 13 '21 at 10:08