DairyKnight
DairyKnight

Reputation: 33

How to prevent jQuery Droppable from accepting certain Draggable?

I'm creating a page with "groups" of droppable widgets, and each draggable can only be dropped on one group of droppables.

I was able to achieve this by the following code:

$("div.droppable").droppable({
    //accept: ".draggable",
    accept: function (draggable) {
        if ($(this).attr("question_id") != null) {
            if ($(this).attr("question_id") == draggable.attr("question_id")) return true;
        }
        return false;
    });

However, now I'm having a little trouble. After dropping, I was not able to move the draggable around droppables in the same group as I could before. I could drop it on a droppable once, move it to another, but I couldn't move it back to the first droppable.

Does anyone know what could have happened? Any input would be appreciated.

Upvotes: 2

Views: 3975

Answers (1)

mekwall
mekwall

Reputation: 28974

No idea what failed in your code. I created this test case on jsFiddle that is working as expected. As seen in this test case, I am using .data to retrieve the question ID.

I hope this helps!

Upvotes: 2

Related Questions