Skip to content

Commit eeec7ac

Browse files
MrKrabatdmitry-kurmanov
authored andcommitted
Fix sortablejs (#14)
Fixed sortable not destroyed Fixed static group name Fixed one value is NULL Fixed min-height
1 parent 0dc96ce commit eeec7ac

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

src/sortablejs.js

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function init(Survey) {
99
return typeof Sortable != "undefined";
1010
},
1111
defaultJSON: { choices: ["Item 1", "Item 2", "Item 3"] },
12-
areaStyle: "border: 1px solid #1ab394; width:100%; minHeight:50px",
12+
areaStyle: "border: 1px solid #1ab394; width:100%; min-height:50px",
1313
itemStyle: "background-color:#1ab394;color:#fff;margin:5px;padding:10px;",
1414
isFit: function(question) {
1515
return question.getType() === "sortablelist";
@@ -74,40 +74,36 @@ function init(Survey) {
7474
});
7575
emptyEl.style.display = wasInResults ? "none" : "";
7676
};
77-
Sortable.create($(resultEl)[0], {
77+
question.resultEl = Sortable.create($(resultEl)[0], {
7878
animation: 150,
79-
group: {
80-
name: "top3",
81-
pull: true,
82-
put: true
83-
},
79+
group: question.name,
8480
onSort: function(evt) {
8581
var result = [];
86-
if (evt.to.children.length === 1) {
82+
if (resultEl.children.length === 1) {
8783
emptyEl.style.display = "";
8884
} else {
8985
emptyEl.style.display = "none";
90-
for (var i = 1; i < evt.to.children.length; i++) {
91-
result.push(evt.to.children[i].dataset.value);
86+
for (var i = 0; i < resultEl.children.length; i++) {
87+
if(typeof resultEl.children[i].dataset.value === 'undefined') continue;
88+
result.push(resultEl.children[i].dataset.value);
9289
}
9390
}
9491
isUpdatingQuestionValue = true;
9592
question.value = result;
9693
isUpdatingQuestionValue = false;
9794
}
9895
});
99-
Sortable.create($(sourceEl)[0], {
96+
question.sourceEl = Sortable.create($(sourceEl)[0], {
10097
animation: 150,
101-
group: {
102-
name: "top3",
103-
pull: true,
104-
put: true
105-
}
98+
group: question.name
10699
});
107100
question.valueChangedCallback = updateValueHandler;
108101
updateValueHandler();
109102
},
110-
willUnmount: function(question, el) {}
103+
willUnmount: function(question, el) {
104+
question.resultEl.destroy();
105+
question.sourceEl.destroy();
106+
}
111107
};
112108

113109
Survey.CustomWidgetCollection.Instance.addCustomWidget(widget, "customtype");

0 commit comments

Comments
 (0)