Skip to content

Commit c4a3f62

Browse files
committed
Fix for the #117 - added clearIncorrectValuesCallback
1 parent 6d82993 commit c4a3f62

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

src/select2.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ function init(Survey, $) {
44
activatedBy: "property",
55
name: "select2",
66
htmlTemplate: "<select style='width: 100%;'></select>",
7-
widgetIsLoaded: function() {
7+
widgetIsLoaded: function () {
88
return typeof $ == "function" && !!$.fn.select2;
99
},
10-
isFit: function(question) {
10+
isFit: function (question) {
1111
if (widget.activatedBy == "property")
1212
return (
1313
question["renderAs"] === "select2" &&
@@ -19,7 +19,7 @@ function init(Survey, $) {
1919
return question.getType() === "select2";
2020
return false;
2121
},
22-
activatedByChanged: function(activatedBy) {
22+
activatedByChanged: function (activatedBy) {
2323
if (!this.widgetIsLoaded()) return;
2424
widget.activatedBy = activatedBy;
2525
Survey.JsonObject.metaData.removeProperty("dropdown", "renderAs");
@@ -42,7 +42,7 @@ function init(Survey, $) {
4242
});
4343
}
4444
},
45-
afterRender: function(question, el) {
45+
afterRender: function (question, el) {
4646
var settings = question.select2Config;
4747
var $el = $(el).is("select") ? $(el) : $(el).find("select");
4848
var othersEl = document.createElement("input");
@@ -55,7 +55,7 @@ function init(Survey, $) {
5555
.get(0)
5656
.appendChild(othersEl);
5757

58-
var updateValueHandler = function() {
58+
var updateValueHandler = function () {
5959
var qText = (typeof question.value === "object")
6060

6161
if ($el.find("option[value='" + question.value + "']").length) {
@@ -72,20 +72,21 @@ function init(Survey, $) {
7272

7373
othersEl.style.display = !question.isOtherSelected ? "none" : "";
7474
};
75-
var updateCommentHandler = function() {
75+
var updateCommentHandler = function () {
7676
othersEl.value = question.comment ? question.comment : "";
7777
};
78-
var othersElChanged = function() {
78+
var othersElChanged = function () {
7979
question.comment = othersEl.value;
8080
};
81-
var updateChoices = function() {
81+
var updateChoices = function () {
8282
$el.select2().empty();
8383

8484
if (settings) {
8585
if (settings.ajax) {
8686
$el.select2(settings);
87+
question.clearIncorrectValuesCallback = function () { };
8788
} else {
88-
settings.data = question.visibleChoices.map(function(choice) {
89+
settings.data = question.visibleChoices.map(function (choice) {
8990
return {
9091
id: choice.value,
9192
text: choice.text
@@ -97,7 +98,7 @@ function init(Survey, $) {
9798
$el.select2({
9899
theme: "classic",
99100
disabled: question.isReadOnly,
100-
data: question.visibleChoices.map(function(choice) {
101+
data: question.visibleChoices.map(function (choice) {
101102
return {
102103
id: choice.value,
103104
text: choice.text
@@ -110,21 +111,21 @@ function init(Survey, $) {
110111
updateCommentHandler();
111112
};
112113

113-
question.readOnlyChangedCallback = function() {
114+
question.readOnlyChangedCallback = function () {
114115
$el.prop("disabled", question.isReadOnly);
115116
};
116117

117118
question.registerFunctionOnPropertyValueChanged(
118119
"visibleChoices",
119-
function() {
120+
function () {
120121
updateChoices();
121122
}
122123
);
123124
updateChoices();
124-
$el.on("select2:select", function(e) {
125+
$el.on("select2:select", function (e) {
125126
question.value = e.target.value;
126127
});
127-
$el.on("select2:unselecting", function(e) {
128+
$el.on("select2:unselecting", function (e) {
128129
question.value = null;
129130
});
130131
othersEl.onchange = othersElChanged;
@@ -133,12 +134,13 @@ function init(Survey, $) {
133134
updateValueHandler();
134135
updateCommentHandler();
135136
},
136-
willUnmount: function(question, el) {
137+
willUnmount: function (question, el) {
137138
$(el)
138139
.find("select")
139140
.off("select2:select")
140141
.select2("destroy");
141142
question.readOnlyChangedCallback = null;
143+
question.clearIncorrectValuesCallback = null;
142144
}
143145
};
144146

0 commit comments

Comments
 (0)