riktar / jkanban

Vanilla Javascript plugin for manage kanban boards
https://www.riccardotartaglia.it/jkanban/
Apache License 2.0
1.07k stars 299 forks source link

Element is null at remove #20

Closed marcosrocha85 closed 5 years ago

marcosrocha85 commented 6 years ago

I am developing a collaborative Kanban for a couple of users and I have a capability of remove items from a board. In that, I call jkanban.removeElement(elementId) to remove a card from current Kanban in order to add at another Kanban (like "Move" of Trello). The problem is when I call jkanban.remove() when the item is not there, jKanban raises a "el is null" error because of:

        this.removeElement = function (el) {
            if (typeof(el) === 'string')
                el = self.element.querySelector('[data-eid="' + el + '"]');
            el.remove(); //<--- here
            return self;
        };

I suggest to add a validation for removeLike methods to verify if element actually exists:

        this.removeElement = function (el) {
            if (typeof(el) === 'string')
                el = self.element.querySelector('[data-eid="' + el + '"]');
            if (el !== null)
                el.remove();
            return self;
        };