Search code examples
jquery-uibackbone.jsdrag-and-dropcoffeescript

jQuery UI Droppable Uncaught TypeError


Having a hard time debugging this one.

Using jQuery UI Droppable in a Backbone application using CoffeeScript.

There is nothing wrong with the functionality, everything is working how I intended it to, but I am still getting this console error every time an item is dropped.

Uncaught TypeError: Cannot read property 'options' of undefined

Code for the droppable:

@$el.droppable
        tolerance: 'pointer'
        hoverClass: 'drop_hover'
        accept: '.item'

        drop: (e, ui) =>
            draggedItem = ui.draggable

            itemId = draggedItem.attr 'data-id'

            allInstances = @model.collection.models

            findItems = for instance in allInstances
                          instanceItems = instance.get 'items'
                          instanceItems.getByCid itemId


            compacted = _.compact findItems

            droppedItem = compacted[0]

            droppedCollection = droppedItem.collection

            droppedCollection.remove droppedItem if _.include droppedCollection.models, droppedItem

            @itemCollection.add droppedItem unless _.include @items, droppedItem

Like I said the functionality is working properly, I just would like to get rid of the error if someone knows anything I could try to debug.

Stack Trace

Uncaught TypeError: Cannot read property 'options' of undefined
a.ui.plugin.add.stopjquery-ui.js:49
a.ui.version.a.extend.plugin.call       jquery-ui.js:9
a.widget._trigger                       jquery-ui.js:49
a.widget._mouseStop                     jquery-ui.js:49
a.widget._mouseUp                       jquery-ui.js:28
a.widget._mouseUp                       jquery-ui.js:49
a.widget._mouseDown._mouseUpDelegate    jquery-ui.js:28
f.event.dispatch                        jquery-1.7.1.min.js:3
f.event.add.h.handle.i                  jquery-1.7.1.min.js:3

Thanks for any help.


Solution

  • This seems to be finally fixed properly in v1.11.0, without all of the workarounds proposed here:

    http://bugs.jqueryui.com/ticket/6889

    It seems that removing the original draggable item now will not result in this error because properties are now stored on the instance field. I've confirmed that v1.11.0 fixes this exact error that popped up on v1.10.4.