Skip to content

Commit

Permalink
Clear incorrect empty values in checkbox, #3062 (#3067)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov committed Jul 8, 2021
1 parent 162254d commit 936bc3a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/question_baseselect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,10 @@ export class QuestionSelectBase extends Question {
protected hasUnknownValue(
val: any,
includeOther: boolean = false,
isFilteredChoices: boolean = true
isFilteredChoices: boolean = true,
checkEmptyValue: boolean = false
): boolean {
if (this.isValueEmpty(val)) return false;
if (!checkEmptyValue && this.isValueEmpty(val)) return false;
if (includeOther && val == this.otherItem.value) return false;
if (this.hasNone && val == this.noneItem.value) return false;
var choices = isFilteredChoices
Expand Down Expand Up @@ -1081,7 +1082,7 @@ export class QuestionSelectBase extends Question {
}
protected canClearValueAnUnknow(val: any): boolean {
if (!this.getStoreOthersAsComment() && this.isOtherSelected) return false;
return this.hasUnknownValue(val, true);
return this.hasUnknownValue(val, true, true, true);
}
protected clearDisabledValuesCore() {
if (this.isValueDisabled(this.value)) {
Expand Down
3 changes: 3 additions & 0 deletions tests/surveyquestiontests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2316,6 +2316,9 @@ QUnit.test("question.clearIncorrectValues", function(assert) {
[],
"clear values, there is no these items in choices"
);
qcheck.value = ["", 0, undefined, null];
qcheck.clearIncorrectValues();
assert.deepEqual(qcheck.value, [], "clear values, clear empty values");
});

QUnit.test("question.clearIncorrectValues and choicesByUrl", function(assert) {
Expand Down

0 comments on commit 936bc3a

Please sign in to comment.