johnny / johnny/jquery-sortable

Question: two nested lists with limited drop targets

Open
#212 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
HTML
Stars
1.5k
Forks
429
PR merge metrics
No merged PRs in 30d

Description

I have two lists: drivers and jobs.

In the jobs list, I can create jobs and orders. They are both a parent element of the list but I want to be able to drop orders on to jobs.

In the drivers list, I only have drivers. I need to be able to drop jobs (with orders attached) on to drivers but not orders.

Right now I have it setup so that Drivers is a list (ol with li). In each Driver list item, there is a ol for jobs. The validation is working for orders to not go to drivers and I can drop jobs on to drivers. When I attach an order to a job, it doesn't pass any validation and won't even go back to its container.

Is there any way to do this?

I can handle the isValidTarget part. I just need to know how to set it up so that all of the lists are droppable.

```
isValidTarget: function ($item, container) {
var parent = $(container.el[0]);

// A job can be dropped in a driver or in the orders container, but not in the driver's container
if($item.is('.job') && parent.is('.driver-orders')) {
return true;
}

// An order can only be dropped on a job or the order's container
if($item.is('.order') && parent.is('.job-orders')) {
return true;
}

// Return it to the parent
return $item.parent('.connectedSortable')[0] == container.el[0];
},
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.