Skip to content

Commit 80b4156

Browse files
committedMar 10, 2025·
A custom new page name localization string (ed.newPageName) is ignore… (#6697)
* A custom new page name localization string (ed.newPageName) is ignored when pages are added via a property grid collection editor fix #6687 * Fix unit tests * Fix unit tests
1 parent c764b9e commit 80b4156

File tree

5 files changed

+51
-6
lines changed

5 files changed

+51
-6
lines changed
 

‎packages/survey-creator-core/src/property-grid/matrices.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ export class PropertyGridEditorMatrixPages extends PropertyGridEditorMatrix {
685685
return "name";
686686
}
687687
protected getBaseValue(prop: JsonObjectProperty): string {
688-
return "page";
688+
return editorLocalization.getString("ed.newPageName");
689689
}
690690
protected getAllowRowDragDrop(prop: JsonObjectProperty): boolean { return true; }
691691
}

‎packages/survey-creator-core/tests/creator-base-v1.tests.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -922,8 +922,8 @@ test("creator.onAddPanel and undo-redo manager, Bug#972", () => {
922922
});
923923

924924
test("SurveyPropertyConditionEditor, set correct locale into internal survey, Bug #953", () => {
925-
editorLocalization.currentLocale = "de";
926925
const creator = new CreatorTester();
926+
editorLocalization.currentLocale = "de";
927927
creator.JSON = {
928928
elements: [
929929
{ name: "q1", type: "text" },
@@ -941,8 +941,8 @@ test("SurveyPropertyConditionEditor, set correct locale into internal survey, Bu
941941
editorLocalization.currentLocale = "";
942942
});
943943
test("creator.onSurveyInstanceCreated, can pass ConditionEditor as model", () => {
944-
editorLocalization.currentLocale = "de";
945944
const creator = new CreatorTester();
945+
editorLocalization.currentLocale = "de";
946946
creator.JSON = {
947947
elements: [
948948
{ name: "q1", type: "text" },

‎packages/survey-creator-core/tests/creator-tester.ts

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export class CreatorTester extends SurveyCreatorModel {
1313
creatorSetting.defaultNewSurveyJSON = { pages: [{ name: "page1" }] };
1414
}
1515
super(options, options2);
16+
//Reset the locale to the default one from the previous tests
17+
this.locale = "";
1618
this.autoSaveDelay = 0;
1719
this.onSurveyInstanceCreated.add((creator, options) => {
1820
options.survey.getRendererForString = (element: Base, name: string): any => {

‎packages/survey-creator-core/tests/property-grid/property-grid.tests.ts

+45-2
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,10 @@ test("dropdown property editor, get choices on callback", () => {
237237
Serializer.removeProperty("survey", "region");
238238
});
239239
test("Serializer.addpropery, type: 'dropdown' cuts the text before dots, provided into choices. Bug#5787", (): any => {
240-
Serializer.addProperty("survey", { name: "prop1:dropdown", type: "dropdown",
241-
choices: ["Gemini 1.5 Pro", "Claude 3.5 Sonnet"] });
240+
Serializer.addProperty("survey", {
241+
name: "prop1:dropdown", type: "dropdown",
242+
choices: ["Gemini 1.5 Pro", "Claude 3.5 Sonnet"]
243+
});
242244
const survey = new SurveyModel();
243245
const propertyGrid = new PropertyGridModelTester(survey);
244246
const question = propertyGrid.survey.getQuestionByName("prop1");
@@ -3324,6 +3326,47 @@ test("check pages editor respects onPageAdding", () => {
33243326
expect(creator.survey.pages.length).toBe(1);
33253327
settings.defaultNewSurveyJSON = savedNewJSON;
33263328
});
3329+
test("Localication and survey.pages property, Bug#6687", () => {
3330+
const deutschStrings: any = {
3331+
ed: {
3332+
newPageName: "Seite"
3333+
}
3334+
};
3335+
editorLocalization.locales["de"] = deutschStrings;
3336+
const creator = new CreatorTester();
3337+
creator.locale = "de";
3338+
creator.JSON = {};
3339+
const propertyGrid = new PropertyGridModelTester(creator.survey);
3340+
const pagesQuestion = <QuestionMatrixDynamicModel>(
3341+
propertyGrid.survey.getQuestionByName("pages")
3342+
);
3343+
const propertyEditor = new PropertyGridEditorMatrixPages();
3344+
const options = { titleActions: [], question: pagesQuestion };
3345+
propertyEditor.onGetQuestionTitleActions(creator.survey, options, creator);
3346+
const addNewPageAction = options.titleActions[0] as IAction;
3347+
3348+
expect(creator.survey.pages.length).toBe(0);
3349+
addNewPageAction.action!();
3350+
3351+
expect(creator.survey.pages.length).toBe(1);
3352+
expect(creator.survey.pages[0].name).toBe("Seite1");
3353+
});
3354+
test("panellayoutcolumns doesn't have adding button", () => {
3355+
const creator = new CreatorTester();
3356+
creator.JSON = {
3357+
gridLayoutEnabled: true,
3358+
elements: [{ type: "text", name: "q1" }]
3359+
};
3360+
const propertyGrid = new PropertyGridModelTester(creator.survey.pages[0]);
3361+
const gridColumnsQuestion = <QuestionMatrixDynamicModel>(propertyGrid.survey.getQuestionByName("gridLayoutColumns"));
3362+
expect(gridColumnsQuestion).toBeTruthy();
3363+
expect(gridColumnsQuestion.allowAddRows).toBeFalsy();
3364+
expect(gridColumnsQuestion.getTitleToolbar()).toBeTruthy();
3365+
const helpButton = gridColumnsQuestion.titleActions.find(a => a.id === "property-grid-help");
3366+
const addButton = gridColumnsQuestion.titleActions.find(a => a.id === "add-item");
3367+
expect(helpButton).toBeTruthy();
3368+
expect(addButton).toBeFalsy();
3369+
});
33273370
test("Set property name into correct category", () => {
33283371
Serializer.addProperty("question", {
33293372
name: "validation",

‎packages/survey-creator-core/tests/tabs/test.tests.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1120,8 +1120,8 @@ test("The Preview Survey button text is not translated Bug#6016", (): any => {
11201120
expect(loc).toBeTruthy();
11211121
if (!loc.ed) loc.ed = {};
11221122
loc.ed.testSurveyAgain = deText;
1123-
editorLocalization.currentLocale = "en";
11241123
const creator: CreatorTester = new CreatorTester();
1124+
editorLocalization.currentLocale = "en";
11251125
expect(creator.locale).toBe("en");
11261126
const testPlugin: TabTestPlugin = <TabTestPlugin>creator.getPlugin("test");
11271127
expect(testPlugin.model).toBeFalsy();

0 commit comments

Comments
 (0)
Please sign in to comment.