Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

items configuration parameter is broken #98

Closed
sagism opened this issue Jan 14, 2014 · 4 comments
Closed

items configuration parameter is broken #98

sagism opened this issue Jan 14, 2014 · 4 comments

Comments

@sagism
Copy link

sagism commented Jan 14, 2014

If you take the multiple lists example, and want to add a title to the lists, you'd normally exclude it from sorting using the items parameter: http://api.jqueryui.com/sortable/#option-items

However, this is not working.
If you do this: (I used both the css class and the ng-class, hoping at least one would work)

List {{$index}}
  <div class="app sortable" ng-class="sortable" ng-repeat="app in screen">{{$index}} {{app.title}}</div>
</div>

...

$scope.sortableOptions = {
placeholder: "app",
connectWith: ".apps-container",
items: "> .sortable"
};

image

See http://codepen.io/anon/pen/brgmk for an example which is based on the one provided here.

The title can be dragged (shouldn't), and if you drag around other items, after a while you end up with bogus items.

@thgreasi
Copy link
Contributor

Here is a fork of your pen demonstrating the lists option for connected lists. So, I believe the title of the issue is not targeting the problem.

This seems to be a duplicate of #41, as the problem is caused by the div you are using for the titles of the lists.
As mentioned in the README

ng-model is required, so that the directive knows which model to update.

Moreover, the elements (and their indexes) of the uiSostable should match the model provided. The simplest rephrase is that uiSortable should only contain a ngRepeat and not any other elements (above or below) as this would break the index matching od the DOM elements generated and the ngModel's items.

Perhaps this should (at last) be mentioned in README.md, because of the frequency this is reported as an issue.

Bonus Points:

  • It isn't semantic to place a title within the same container with the items of a list. So move it outside the directive.
  • use ul/ol & li's to be even more semantic (the above point was a reason ul was used in the demo pens).

@sagism
Copy link
Author

sagism commented Jan 14, 2014

Thanks for the quick and detailed response.
However, I disagree with your assessment.

This is exactly what the ui-sortable "items" parameter is intended for, to cherry-pick which items to activate the sortable on.
angular-ui-sortable states that "All the jQueryUI Sortable options can be passed through the directive", but does not respect this parameter's intent.
regarding "ng-model is required...", ng-model is declared there unmodified from the example provided in the readme at http://codepen.io/thgreasi/pen/apwsb
Ditto regarding the use of divs vs. list elements. This is just the way it is in the demo provided in the readme and I wanted to minimize the changes I made to the original.

Regarding your suggested solution, it does not achieve the intent of adding a title to the list, which references the model, and therefore needs to be inside the ngRepeat, If you have a suggestion to this need, would love to see it.

@thgreasi
Copy link
Contributor

Ok, let me show you a somewhat better solution. Also works with <div>s.
I think that my pen demonstrated (in an isolated use case) that the items option works.
Please place the title outside of the directive, if this is not a huge change for your code.

In other words... In the current state of the directive, only one ng-repeat element (and only this element) can be inside the ui-sortable directive. Patches welcome as mentioned in #41.

@sagism
Copy link
Author

sagism commented Jan 14, 2014

Thanks. Your suggestion is indeed a decent workaround and solves my problem.
I wish I could suggest a fix, but I'm a beginner at angular so it's quite a few notches above my comfort level...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants