Skip to content

Commit

Permalink
Radiogroup | Clear button caption remains untranslated if survey.loca…
Browse files Browse the repository at this point in the history
…le is changed after a form is rendered fix #9113 (#9117)
  • Loading branch information
andrewtelnov authored Nov 28, 2024
1 parent b3718af commit ba91144
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/survey-core/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,8 @@ export class Base {
public getProgressInfo(): IProgressInfo {
return Base.createProgressInfo();
}
public localeChanged() { }
public locStrsChanged() {
public localeChanged(): void { }
public locStrsChanged(): void {
if (!!this.arraysInfo) {
for (let key in this.arraysInfo) {
let item = this.arraysInfo[key];
Expand Down
2 changes: 1 addition & 1 deletion packages/survey-core/src/question_radiogroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class QuestionRadiogroupModel extends QuestionCheckboxBase {
if(this.isDefaultV2Theme && !this.isDesignMode) {
const clearAction = new Action(
{
title: this.clearButtonCaption,
locTitleName: "clearCaption",
id: `sv-clr-btn-${this.id}`,
action: () => { this.clearValue(true); },
innerCss: this.cssClasses.clearButton,
Expand Down
7 changes: 7 additions & 0 deletions packages/survey-core/src/survey-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ export class SurveyElement<E = any> extends SurveyElementCore implements ISurvey
public getTitleToolbar(): AdaptiveActionContainer {
if (!this.titleToolbarValue) {
this.titleToolbarValue = <AdaptiveActionContainer>this.createActionContainer(true);
this.titleToolbarValue.locOwner = this;
this.titleToolbarValue.containerCss = (this.isPanel ? this.cssClasses.panel.titleBar : this.cssClasses.titleBar) || "sv-action-title-bar";
this.titleToolbarValue.setItems(this.getTitleActions());
}
Expand Down Expand Up @@ -485,6 +486,12 @@ export class SurveyElement<E = any> extends SurveyElementCore implements ISurvey
}
this.setPropertyValue("titleActions", actions);
}
public locStrsChanged(): void {
super.locStrsChanged();
if(!!this.titleToolbarValue) {
this.titleToolbarValue.locStrsChanged();
}
}
public get hasTitleActions(): boolean {
return this.getTitleActions().length > 0;
}
Expand Down
16 changes: 16 additions & 0 deletions packages/survey-core/tests/question_baseselecttests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2330,3 +2330,19 @@ QUnit.test("question checkbox add a custom property into choicesByUrl, Bug#8783"
assert.deepEqual(q1.toJSON(), { name: "q1", choicesByUrl: { valueName: "name", jsonpath: "newpath" } }, "#2");
Serializer.removeProperty("choicesByUrl", "jsonpath");
});
QUnit.test("Clear action in locale & survey.locale change, Bug#9113", (assert) => {
const survey = new SurveyModel();
survey.css =survey.css = { root: "sd-root-modern" };
survey.fromJSON({
elements: [{ type: "radiogroup", name: "q1", showClearButton: true }]
});
const q1 = <QuestionRadiogroupModel>survey.getQuestionByName("q1");
assert.equal(q1.isDefaultV2Theme, true, "V2 theme");
assert.ok(q1.getTitleToolbar());
assert.equal(q1.titleActions.length, 1, "one action");
const item = q1.titleActions[0];
assert.equal(item.locTitle.localizationName, "clearCaption", "locName");
assert.equal(item.locTitle.locale, "", "locale #1");
survey.locale = "de";
assert.equal(item.locTitle.locale, "de", "locale #2");
});

0 comments on commit ba91144

Please sign in to comment.