Skip to content

Enable "fast entry" for choices even when visibleIf or enableIf are u… #6861

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions packages/survey-creator-core/src/property-grid/matrices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,7 @@ export class PropertyGridEditorMatrixItemValues extends PropertyGridEditorMatrix
!!column &&
column.isVisible &&
!column.readOnly &&
!this.hasMultipleLanguage(items) &&
!this.hasVisibleIfOrEnableIf(items)
!this.hasMultipleLanguage(items)
);
}
protected getAllowRowDragDrop(prop: JsonObjectProperty): boolean { return true; }
Expand All @@ -482,7 +481,15 @@ export class PropertyGridEditorMatrixItemValues extends PropertyGridEditorMatrix
question: Question,
options: ISurveyCreatorOptions
): IPropertyEditorSetup {
var names = (<any>question).columns.filter(c => !c.readOnly).map(c => c.name);
const names = (<any>question).columns.filter(c => !c.readOnly).map(c => c.name);
const visibleIfProp = Serializer.findProperty("itemvalue", "visibleIf");
if (visibleIfProp && visibleIfProp.visible) {
names.push("visibleIf");
const enableIfProp = Serializer.findProperty("itemvalue", "enableIf");
if (enableIfProp && enableIfProp.visible) {
names.push("enableIf");
}
}
return new FastEntryEditor(obj[prop.name], options, prop.className, names);
}
public canClearPropertyValue(
Expand Down Expand Up @@ -543,17 +550,6 @@ export class PropertyGridEditorMatrixItemValues extends PropertyGridEditorMatrix
}
return false;
}
private hasVisibleIfOrEnableIf(items: Array<ItemValue>): boolean {
if (!items || !Array.isArray(items)) {
return false;
}
for (var i = 0; i < items.length; i++) {
if (!!items[i].visibleIf || items[i].enableIf) {
return true;
}
}
return false;
}
public onMatrixCellCreated(obj: Base, options: any): void {
super.onMatrixCellCreated(obj, options);
function updateHtml(question, value) {
Expand Down
126 changes: 123 additions & 3 deletions packages/survey-creator-core/tests/property-grid/fast-entry.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FastEntryEditor } from "../../src/property-grid/fast-entry";
import { ItemValue, QuestionRadiogroupModel, QuestionTextBase, Serializer } from "survey-core";
import { ItemValue, QuestionRadiogroupModel, QuestionDropdownModel, QuestionTextBase, Serializer } from "survey-core";
import { EmptySurveyCreatorOptions } from "../../src/creator-settings";

test("Create survey with editingObj", () => {
Expand Down Expand Up @@ -164,14 +164,14 @@ test("Custom properties, Bug#6753", () => {
Serializer.addProperty("itemvalue", { name: "leftName:text" });
Serializer.addProperty("itemvalue", { name: "rightName:text" });
const originalElement = new QuestionRadiogroupModel("q1");
originalElement.choices = ["item1", "item2", "item2"];
originalElement.choices = ["item1", "item2", "item3"];
const choices = originalElement.choices;
choices[0].leftName = "left1";
choices[0].rightName = "right1";
choices[2].leftName = "left3";
choices[2].rightName = "right3";
const fastEntryEditor = new FastEntryEditor(choices, new EmptySurveyCreatorOptions(), undefined, ["value", "text", "leftName", "rightName"]);
expect(fastEntryEditor.comment.value).toEqual("item1||left1|right1\nitem2\nitem2||left3|right3");
expect(fastEntryEditor.comment.value).toEqual("item1||left1|right1\nitem2\nitem3||left3|right3");
fastEntryEditor.comment.value = "item3||left3|right3\nitem2\nitem1||left1|right1\n";
fastEntryEditor.apply();
expect(originalElement.choices).toHaveLength(3);
Expand All @@ -187,3 +187,123 @@ test("Custom properties, Bug#6753", () => {
Serializer.removeProperty("itemvalue", "leftName");
Serializer.removeProperty("itemvalue", "rightName");
});
test("SurveyHelper.applyItemValueArray", () => {
var q1 = new QuestionDropdownModel("q1");
var q2 = new QuestionDropdownModel("q1");
q1.choices = [1];
new FastEntryEditor([]).applyItemValueArray(q1.choices, null);
expect(q1.choices).toHaveLength(0);
q1.choices = [1];
q2.choices = [];
new FastEntryEditor([]).applyItemValueArray(q1.choices, q2.choices);
expect(q1.choices).toHaveLength(0);
var testSetFunc = function (val1: Array<any>, val2: Array<any>, num: number) {
q1.choices = val1;
q2.choices = val2;
new FastEntryEditor([]).applyItemValueArray(q1.choices, q2.choices);
expect(q1.toJSON()).toEqual(q2.toJSON());
};
testSetFunc([1, 2, 3], [1, 2, 4], 1);
testSetFunc([1, 2, 3], [1, 2, 4, 5], 2);
testSetFunc([1, 2, 3], [0, 1, 2, 3], 3);
testSetFunc([1, 2, 3], [1, 4, 3], 4);
testSetFunc([1, 2, 3], [1, 2, 3, 4, 5, 6], 5);
testSetFunc([1, 2, 3, 4, 5, 6], [1, 2, 3], 6);
testSetFunc(
[1, 2, 3],
[1, { value: 2, text: "item 2" }, { value: 4, text: "item 4" }],
7
);
testSetFunc([1, 2, 2, 3, 4, 5, 6], [1, 2, 2, 3], 8);
testSetFunc([1, 2, 3, 4, 2, 5, 6], [1, 2, 3, 2], 9);
testSetFunc(
[1, 2, 13, 14, 5, 6],
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
10
);
});
test("Setup choices from FastEntryEditor", () => {
var choices = new Array<ItemValue>();
var editor = new FastEntryEditor(choices);
editor.comment.value = "1|One\n2|Two";
editor.apply();
expect(choices).toHaveLength(2);
expect(choices[0].value).toEqual("1");
expect(choices[0].text).toEqual("One");
expect(choices[1].value).toEqual("2");
expect(choices[1].text).toEqual("Two");
});
test("Empty choices from FastEntryEditor, Bug#4733", () => {
var choices = new Array<ItemValue>();
choices.push(new ItemValue(1));
choices.push(new ItemValue(2));
var editor = new FastEntryEditor(choices);
editor.comment.value = "";
editor.apply();
expect(choices).toHaveLength(0);
});
test("SurveyHelper convertTextToItemValues", () => {
var choices = new Array<ItemValue>();
choices.push(new ItemValue(1));
choices.push(new ItemValue("itemValue", "itemText"));
choices.push(new ItemValue("2"));

var editor = new FastEntryEditor(choices);
expect(editor.comment.value).toEqual("1\nitemValue|itemText\n2");
});
test("visibleIf&enableIf support, Bug#6857", () => {
const originalElement = new QuestionRadiogroupModel("q1");
originalElement.choices = ["item1", "item2", "item3"];
const choices = originalElement.choices;
choices[0].visibleIf = "{a}=1";
choices[0].enableIf = "{b}=1";
choices[2].visibleIf = "{a}=3";
choices[2].enableIf = "{b}=3";
const fastEntryEditor = new FastEntryEditor(choices, new EmptySurveyCreatorOptions(), undefined, ["value", "text", "visibleIf", "enableIf"]);
expect(fastEntryEditor.comment.value).toEqual("item1||{a}=1|{b}=1\nitem2\nitem3||{a}=3|{b}=3");
fastEntryEditor.comment.value = "item3||{a}=3|{b}=3\nitem2\nitem1||{a}=1|{b}=1\n";
fastEntryEditor.apply();
expect(originalElement.choices).toHaveLength(3);
expect(choices[0].value).toEqual("item3");
expect(choices[0].visibleIf).toBe("{a}=3");
expect(choices[0].enableIf).toBe("{b}=3");
expect(choices[1].value).toEqual("item2");
expect(choices[1].visibleIf).toBeFalsy();
expect(choices[1].enableIf).toBeFalsy();
expect(choices[2].value).toEqual("item1");
expect(choices[2].visibleIf).toBe("{a}=1");
expect(choices[2].enableIf).toBe("{b}=1");
});
test("Custom properties vs visibleIf&enableIf, Bug#6857", () => {
Serializer.addProperty("itemvalue", { name: "leftName:text" });
Serializer.addProperty("itemvalue", { name: "rightName:text" });
const originalElement = new QuestionRadiogroupModel("q1");
originalElement.choices = ["item1", "item2", "item3"];
const choices = originalElement.choices;
choices[0].leftName = "left1";
choices[0].rightName = "right1";
choices[0].visibleIf = "{a}=1";
choices[1].enableIf = "{b}=2";
choices[2].leftName = "left3";
choices[2].rightName = "right3";
choices[2].visibleIf = "{a}=3";
choices[2].enableIf = "{b}=3";
const fastEntryEditor = new FastEntryEditor(choices, new EmptySurveyCreatorOptions(), undefined, ["value", "text", "leftName", "rightName", "visibleIf", "enableIf"]);
expect(fastEntryEditor.comment.value).toEqual("item1||left1|right1|{a}=1\nitem2|||||{b}=2\nitem3||left3|right3|{a}=3|{b}=3");
fastEntryEditor.comment.value = "item3||left3|right3|{a}=3\nitem2\nitem1||left1|right1||{b}=1\n";
fastEntryEditor.apply();
expect(originalElement.choices).toHaveLength(3);
expect(choices[0].value).toEqual("item3");
expect(choices[0].leftName).toBe("left3");
expect(choices[0].rightName).toBe("right3");
expect(choices[0].visibleIf).toBe("{a}=3");
expect(choices[1].value).toEqual("item2");
expect(choices[1].leftName).toBeFalsy();
expect(choices[1].rightName).toBeFalsy();
expect(choices[2].value).toEqual("item1");
expect(choices[2].leftName).toBe("left1");
expect(choices[2].rightName).toBe("right1");
expect(choices[2].enableIf).toBe("{b}=1");
Serializer.removeProperty("itemvalue", "leftName");
Serializer.removeProperty("itemvalue", "rightName");
});
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import { PropertyGridEditorCondition } from "../../src/property-grid/condition";
import { ConditionEditor } from "../../src/property-grid/condition-survey";
import { DefaultValueEditor } from "../../src/property-grid/values-survey";
import { PropertyGridValueEditor } from "../../src/property-grid/values";
import { FastEntryEditor } from "../../src/property-grid/fast-entry";
import { PropertyGridModelTester, findSetupAction } from "./property-grid.base";

export * from "../../src/property-grid/bindings";
Expand Down Expand Up @@ -1689,42 +1688,6 @@ test("expression editor in question expression validator should has access to su
expect(conditionEditor.survey.getAllQuestions()).toHaveLength(3);
});

test("SurveyHelper.applyItemValueArray", () => {
var q1 = new QuestionDropdownModel("q1");
var q2 = new QuestionDropdownModel("q1");
q1.choices = [1];
new FastEntryEditor([]).applyItemValueArray(q1.choices, null);
expect(q1.choices).toHaveLength(0);
q1.choices = [1];
q2.choices = [];
new FastEntryEditor([]).applyItemValueArray(q1.choices, q2.choices);
expect(q1.choices).toHaveLength(0);
var testSetFunc = function (val1: Array<any>, val2: Array<any>, num: number) {
q1.choices = val1;
q2.choices = val2;
new FastEntryEditor([]).applyItemValueArray(q1.choices, q2.choices);
expect(q1.toJSON()).toEqual(q2.toJSON());
};
testSetFunc([1, 2, 3], [1, 2, 4], 1);
testSetFunc([1, 2, 3], [1, 2, 4, 5], 2);
testSetFunc([1, 2, 3], [0, 1, 2, 3], 3);
testSetFunc([1, 2, 3], [1, 4, 3], 4);
testSetFunc([1, 2, 3], [1, 2, 3, 4, 5, 6], 5);
testSetFunc([1, 2, 3, 4, 5, 6], [1, 2, 3], 6);
testSetFunc(
[1, 2, 3],
[1, { value: 2, text: "item 2" }, { value: 4, text: "item 4" }],
7
);
testSetFunc([1, 2, 2, 3, 4, 5, 6], [1, 2, 2, 3], 8);
testSetFunc([1, 2, 3, 4, 2, 5, 6], [1, 2, 3, 2], 9);
testSetFunc(
[1, 2, 13, 14, 5, 6],
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
10
);
});

test("property editor titleQuestion.description", () => {
var survey = new SurveyModel();
survey.addNewPage("p");
Expand Down Expand Up @@ -1838,37 +1801,6 @@ test("SurveyPropertyDefaultValueEditor: Default Value Title", () => {
);
expect(editorLocalization.getString("pe.defaultValue")).toEqual(defaultValueQuestion.title);
});

test("Setup choices from FastEntryEditor", () => {
var choices = new Array<ItemValue>();
var editor = new FastEntryEditor(choices);
editor.comment.value = "1|One\n2|Two";
editor.apply();
expect(choices).toHaveLength(2);
expect(choices[0].value).toEqual("1");
expect(choices[0].text).toEqual("One");
expect(choices[1].value).toEqual("2");
expect(choices[1].text).toEqual("Two");
});
test("Empty choices from FastEntryEditor, Bug#4733", () => {
var choices = new Array<ItemValue>();
choices.push(new ItemValue(1));
choices.push(new ItemValue(2));
var editor = new FastEntryEditor(choices);
editor.comment.value = "";
editor.apply();
expect(choices).toHaveLength(0);
});
test("SurveyHelper convertTextToItemValues", () => {
var choices = new Array<ItemValue>();
choices.push(new ItemValue(1));
choices.push(new ItemValue("itemValue", "itemText"));
choices.push(new ItemValue("2"));

var editor = new FastEntryEditor(choices);
expect(editor.comment.value).toEqual("1\nitemValue|itemText\n2");
});

test("SurveyPropertyDefaultValueEditor json properties filtering", () => {
PropertyGridEditorCollection.register(new PropertyGridValueEditor());
var question = new QuestionTextModel("q1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1443,7 +1443,7 @@ test("options.onSetPropertyEditorOptionsCallback", () => {
expect(actions[1].enabled).toBeFalsy();
expect(updater()).toBeFalsy();
});
test("property-grid-setup action dynamic enabled property Bug#6751", () => {
test.skip("We decided to support editing visibleIf/enableIf. property-grid-setup action dynamic enabled property Bug#6751", () => {
const question1 = new QuestionDropdownModel("q1");
question1.choices = [1, 2, 3];
const propertyGrid = new PropertyGridModelTester(question1);
Expand All @@ -1461,6 +1461,17 @@ test("property-grid-setup action dynamic enabled property Bug#6751", () => {
visibleIfQuestion.value = "";
expect(action.enabled).toBeTruthy();
});
test.skip("property-grid-setup disable for multiple", () => {
const question1 = new QuestionDropdownModel("q1");
question1.choices = [1, { value: 2, text: { default: "t1", de: "t2" } }, 3];
const propertyGrid = new PropertyGridModelTester(question1);
const choicesQuestion = <QuestionMatrixDynamicModel>(
propertyGrid.survey.getQuestionByName("choices")
);
const action = choicesQuestion.getTitleToolbar().getActionById("property-grid-setup");
expect(action).toBeTruthy();
expect(action.enabled).toBeFalsy();
});
test("options.onSetPropertyEditorOptionsCallback - allowBatchEdit", () => {
const options = new EmptySurveyCreatorOptions();
var propName = "";
Expand Down