Skip to content

Commit 6e1c17a

Browse files
committed
Fix: tagbox doesn't remove items if value is number #273
1 parent 54d7de1 commit 6e1c17a

File tree

11 files changed

+161
-105
lines changed

11 files changed

+161
-105
lines changed

examples/angular/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
type="text/css" rel="stylesheet" />
3131
<!-- bootstrap-datepicker -->
3232
<!-- jquery-ui-datepicker -->
33-
<script src="https://unpkg.com/jquery"></script>
3433
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
3534
<link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/themes/smoothness/jquery-ui.css" type="text/css"
3635
rel="stylesheet" />

examples/jquery/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
type="text/css" rel="stylesheet" />
2020
<!-- bootstrap-datepicker -->
2121
<!-- jquery-ui-datepicker -->
22-
<script src="https://unpkg.com/jquery"></script>
2322
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
2423
<link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/themes/smoothness/jquery-ui.css" type="text/css"
2524
rel="stylesheet" />

examples/knockout/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
type="text/css" rel="stylesheet" />
2222
<!-- bootstrap-datepicker -->
2323
<!-- jquery-ui-datepicker -->
24-
<script src="https://unpkg.com/jquery"></script>
2524
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
2625
<link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/themes/smoothness/jquery-ui.css" type="text/css"
2726
rel="stylesheet" />

examples/react/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
type="text/css" rel="stylesheet" />
2626
<!-- bootstrap-datepicker -->
2727
<!-- jquery-ui-datepicker -->
28-
<script src="https://unpkg.com/jquery"></script>
2928
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
3029
<link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/themes/smoothness/jquery-ui.css" type="text/css"
3130
rel="stylesheet" />

examples/vue/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
type="text/css" rel="stylesheet" />
2222
<!-- bootstrap-datepicker -->
2323
<!-- jquery-ui-datepicker -->
24-
<script src="https://unpkg.com/jquery"></script>
2524
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
2625
<link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/themes/smoothness/jquery-ui.css" type="text/css"
2726
rel="stylesheet" />

package-lock.json

Lines changed: 91 additions & 91 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"build": "webpack --env.buildType prod",
99
"release": "standard-version --message \"Release: %s [skip ci]\"",
1010
"testcafe": "concurrently \"http-server --silent\" \"testcafe -c 4 chrome testcafe/ --selector-timeout 1500\"",
11-
"testcafe:ci": "http-server --silent & testcafe chrome:headless testcafe/ --selector-timeout 1500 "
11+
"testcafe:ci": "http-server --silent & testcafe chrome:headless testcafe/ --selector-timeout 1500 ",
12+
"testcafe_file": "concurrently \"http-server --silent\" \"testcafe chrome testCafe/tagbox.ts --selector-timeout 1500 --reporter minimal\""
1213
},
1314
"repository": {
1415
"type": "git",
@@ -45,4 +46,4 @@
4546
"virtual-module-webpack-plugin": "^0.3.0",
4647
"webpack": "^3.6.0"
4748
}
48-
}
49+
}

src/select2-tagbox.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,20 @@ function init(Survey, $) {
158158
updateComment();
159159
});
160160
$el.on("select2:unselect", function (e) {
161-
var index = (question.value || []).indexOf(e.params.data.id);
162-
if (isAllItemSelected(e.params.data.id)) {
161+
const select2Val = e.params.data.id;
162+
if (isAllItemSelected(select2Val)) {
163163
question.clearValue();
164-
} else if (index !== -1) {
165-
var val = [].concat(question.value);
166-
val.splice(index, 1);
167-
question.value = val;
164+
} else {
165+
const val = [].concat(question.value);
166+
if(Array.isArray(val)) {
167+
for(var i = 0; i < val.length; i ++) {
168+
if(val[i] == select2Val || (!!val[i] && val[i].toString() == select2Val)) {
169+
val.splice(i, 1);
170+
question.value = val;
171+
break;
172+
}
173+
}
174+
}
168175
}
169176
updateComment();
170177
});

testcafe/all-widgets.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var json = {
1717
{
1818
type: "dropdown",
1919
renderAs: "select2",
20-
choicesByUrl: { url: "https://restcountries.eu/rest/v1/all" },
20+
choicesByUrl: { url: "https://surveyjs.io/api/CountriesExample" },
2121
name: "countries",
2222
},
2323
{

testcafe/helper.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,7 @@ export const initSurvey = ClientFunction(
5757
window.survey = model;
5858
}
5959
);
60+
export const getData = ClientFunction(() => {
61+
return survey.data;
62+
});
6063

0 commit comments

Comments
 (0)