{"action":"created","issue":{"url":"https://api.github.com/repos/johnny/jquery-sortable/issues/132","labels_url":"https://api.github.com/repos/johnny/jquery-sortable/issues/132/labels{/name}","comments_url":"https://api.github.com/repos/johnny/jquery-sortable/issues/132/comments","events_url":"https://api.github.com/repos/johnny/jquery-sortable/issues/132/events","html_url":"https://github.com/johnny/jquery-sortable/issues/132","id":41073761,"number":132,"title":"Groups stop working from within a modal view","user":{"login":"alxndrmlr","id":579553,"avatar_url":"https://avatars.githubusercontent.com/u/579553?v=3","gravatar_id":"","url":"https://api.github.com/users/alxndrmlr","html_url":"https://github.com/alxndrmlr","followers_url":"https://api.github.com/users/alxndrmlr/followers","following_url":"https://api.github.com/users/alxndrmlr/following{/other_user}","gists_url":"https://api.github.com/users/alxndrmlr/gists{/gist_id}","starred_url":"https://api.github.com/users/alxndrmlr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alxndrmlr/subscriptions","organizations_url":"https://api.github.com/users/alxndrmlr/orgs","repos_url":"https://api.github.com/users/alxndrmlr/repos","events_url":"https://api.github.com/users/alxndrmlr/events{/privacy}","received_events_url":"https://api.github.com/users/alxndrmlr/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/johnny/jquery-sortable/labels/docs","name":"docs","color":"009800"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2014-08-25T15:39:05Z","updated_at":"2015-04-18T04:09:28Z","closed_at":null,"body":"Note: **bold** keywords refer to concepts from my application logic\r\n\r\nI've setup the plugin for allowing my users to sort lists of **Criteria** and **Criteria Groups** wherein a **Criteria** belongs to 0..1 **Criteria Groups**\r\n\r\nThe following function is used within my application to setup the sortable lists. The challenge I've run into is we're loading this inside of a modal framework (http://jquery.iceburg.net/jqModal/) which works fine, however when I hide and show the modal again the group names don't work. (I'm thinking this is because the destroy code isn't called *on hide* thus when call ``initSortableLists()`` we call destroy un-initialized sortable objects, then create the new ones. All that being said, I wouldn't think that this should create a problem with the groups, however unless I change the group name on load (right now by adding ``Date.now()`` I can drag the rows but they have no target to land.\r\n\r\n    function initSortableLists() {\r\n        var criteriaList = $(\"ol.criteria\");\r\n        var criteriaGroupsList = $(\"ol.criteria_group\");\r\n\r\n        criteriaList.sortable(\"destroy\");\r\n        criteriaGroupsList.sortable(\"destroy\");\r\n\r\n        criteriaList.sortable({\r\n            // This pluggin appears to have an issue when we do a jqmHardHide()\r\n            // the jqmShow() wherein iff the name of the criteria group is the same\r\n            // as what it was before then the drag and drop won't work.\r\n            group: 'criteria'+Date.now(),\r\n            pullPlaceholder: false,\r\n            handle: \".dragger\",\r\n            tolerance: 25,\r\n            placeholder: '<li class=\"placeholder\"><span class=\"placeholderText\">Drop Here</span></li>',\r\n            onDrop: function (item, container, _super, event) {\r\n                $(item).removeClass(\"dragged\").removeAttr(\"style\");\r\n                $(\"body\").removeClass(\"dragging\");\r\n                $(item).addClass(\"changed-row\");\r\n                var formKey = $(item).data('formkey');\r\n                var criteriaSetIdInputName = formKey+'[CriteriaSetID]';\r\n                var criteriaSetId = $(container.el).siblings('.criteriaSetButtons').data('criteriasetid')\r\n                $(\"input[name='\"+criteriaSetIdInputName+\"']\").val(criteriaSetId);\r\n                reNumberRows();\r\n                calculateCriteriaSetPoints();\r\n                showSubmitStrip();\r\n            }\r\n        });\r\n\r\n        criteriaGroupsList.sortable({\r\n            group: 'criteria_group'+Date.now(),\r\n            nested: false,\r\n            pullPlaceholder: false,\r\n            handle: \".dragger\",\r\n            tolerance: 25,\r\n            placeholder: '<li class=\"placeholder\"><span class=\"placeholderText\">Drop Here</span></li>',\r\n            isValidTarget: function  (item, container) {\r\n                if(item.is(\".criteria\"))\r\n                    return true\r\n                else {\r\n                    return item.parent(\"ol\")[0] == container.el[0]\r\n                }\r\n            },\r\n            onDrop: function (item, container, _super, event) {\r\n                $(item).removeClass(\"dragged\").removeAttr(\"style\");\r\n                $(\"body\").removeClass(\"dragging\");\r\n                $(item).children(\".criteriaSetForm\").addClass(\"changed-row\");\r\n                reNumberRows();\r\n                calculateCriteriaSetPoints();\r\n                showSubmitStrip();\r\n            }\r\n        });\r\n    }\r\n\r\nI hope the above gives enough context, essentially if I try to destroy then re-int sortable after the original DOM elems have been removed and replaced the a constant group name make it so I have no targets to place the dragged rows, however if I change the group name on each init everything works fine."},"comment":{"url":"https://api.github.com/repos/johnny/jquery-sortable/issues/comments/94123742","html_url":"https://github.com/johnny/jquery-sortable/issues/132#issuecomment-94123742","issue_url":"https://api.github.com/repos/johnny/jquery-sortable/issues/132","id":94123742,"user":{"login":"hiep8024","id":1776366,"avatar_url":"https://avatars.githubusercontent.com/u/1776366?v=3","gravatar_id":"","url":"https://api.github.com/users/hiep8024","html_url":"https://github.com/hiep8024","followers_url":"https://api.github.com/users/hiep8024/followers","following_url":"https://api.github.com/users/hiep8024/following{/other_user}","gists_url":"https://api.github.com/users/hiep8024/gists{/gist_id}","starred_url":"https://api.github.com/users/hiep8024/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hiep8024/subscriptions","organizations_url":"https://api.github.com/users/hiep8024/orgs","repos_url":"https://api.github.com/users/hiep8024/repos","events_url":"https://api.github.com/users/hiep8024/events{/privacy}","received_events_url":"https://api.github.com/users/hiep8024/received_events","type":"User","site_admin":false},"created_at":"2015-04-18T04:09:28Z","updated_at":"2015-04-18T04:09:28Z","body":"Thank alxndrmlr, It's really help me to save my time!"}}