Skip to content

Commit 45ac545

Browse files
authored
Choices Batch Editor treats the 0 numeric value as a nullish value and displays an empty string fix #6716 (#6719)
1 parent 480366b commit 45ac545

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

packages/survey-creator-core/src/property-grid/fast-entry.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ItemValue, QuestionCommentModel, QuestionTextBase, Serializer, Base } from "survey-core";
1+
import { ItemValue, QuestionCommentModel, QuestionTextBase, Serializer, Base, Helpers } from "survey-core";
22
import { PropertyEditorSetupValue } from "./index";
33
import { ISurveyCreatorOptions } from "../creator-settings";
44
import { editorLocalization } from "../editorLocalization";
@@ -154,13 +154,14 @@ export class FastEntryEditorBase extends PropertyEditorSetupValue {
154154
protected collectNames(item, type: string, separatorCounter: number): string {
155155
let text: string = "";
156156
this.names.forEach((name) => {
157+
let str = undefined;
157158
if (type === "itemvalues") {
158159
if (name == "value") return;
159-
var str = name == "text" ? item.pureText : item[name];
160+
str = name == "text" ? item.pureText : item[name];
160161
} else {
161-
var str = item[name];
162+
str = item[name];
162163
}
163-
if (!!str) {
164+
if (!Helpers.isValueEmpty(str)) {
164165
for (var i = 0; i < separatorCounter; i++) {
165166
text += ItemValue.Separator;
166167
}

packages/survey-creator-core/tests/property-grid/fast-entry.test.ts

+21
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,24 @@ test("Do not re-create with the same item.value", () => {
139139
expect(choices[5].value).toEqual("item8");
140140
expect(choices[5].getPropertyValue("#id")).toBeUndefined();
141141
});
142+
test("Work correctly with 0 number, Bug#6716", () => {
143+
Serializer.addProperty("itemvalue", { name: "score:number" });
144+
const originalElement = new QuestionRadiogroupModel("originalElement");
145+
originalElement.choices = ["item1", "item2", "item2"];
146+
const choices = originalElement.choices;
147+
choices[0].score = 0;
148+
choices[1].score = 1;
149+
choices[2].score = 0;
150+
const fastEntryEditor = new FastEntryEditor(choices, new EmptySurveyCreatorOptions(), undefined, ["value", "text", "score"]);
151+
expect(fastEntryEditor.comment.value).toEqual("item1||0\nitem2||1\nitem2||0");
152+
fastEntryEditor.comment.value = "item1||1\nitem2||0\nitem3||3";
153+
fastEntryEditor.apply();
154+
expect(originalElement.choices).toHaveLength(3);
155+
expect(choices[0].value).toEqual("item1");
156+
expect(choices[0].score).toBe("1");
157+
expect(choices[1].value).toEqual("item2");
158+
expect(choices[1].score).toBe("0");
159+
expect(choices[2].value).toEqual("item3");
160+
expect(choices[2].score).toBe("3");
161+
Serializer.removeProperty("itemvalue", "score");
162+
});

0 commit comments

Comments
 (0)