Skip to content

Commit 9b162d7

Browse files
authored
Remove creator event subscription in string editor on detachFromUI (#6721)
1 parent 231fd56 commit 9b162d7

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

packages/survey-creator-core/src/components/string-editor.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ export class StringEditorViewModelBase extends Base {
256256
super();
257257
this.locString = locString;
258258
this.checkMarkdownToTextConversion(this.locString.owner, this.locString.name);
259-
this.creator?.onLocaleChanded.add(this.onLocaleChanged);
259+
this.addCreatorEvents();
260260
}
261261
private onLocaleChanged = () => {
262262
this.resetPropertyValue("placeholderValue");
@@ -268,6 +268,7 @@ export class StringEditorViewModelBase extends Base {
268268
}
269269

270270
public detachFromUI() {
271+
this.removeCreatorEvents();
271272
this.connector?.onDoActivate.remove(this.activate);
272273
this.getEditorElement = undefined;
273274
this.blurEditor = undefined;
@@ -278,7 +279,12 @@ export class StringEditorViewModelBase extends Base {
278279
super.dispose();
279280
this.detachFromUI();
280281
}
281-
282+
private addCreatorEvents() {
283+
this.creator?.onLocaleChanded.add(this.onLocaleChanged);
284+
}
285+
private removeCreatorEvents() {
286+
this.creator?.onLocaleChanded.remove(this.onLocaleChanged);
287+
}
282288
public activate = () => {
283289
const element = this.getEditorElement();
284290
if (element && element.offsetParent != null) {
@@ -290,10 +296,12 @@ export class StringEditorViewModelBase extends Base {
290296
}
291297

292298
public setLocString(locString: LocalizableString) {
299+
this.removeCreatorEvents();
293300
this.connector?.onDoActivate.remove(this.activate);
294301
this.locString = locString;
295302
this.connector = StringEditorConnector.get(locString);
296303
this.connector.onDoActivate.add(this.activate);
304+
this.addCreatorEvents();
297305
}
298306
public checkConstraints(event: any) {
299307
if (!this.compostionInProgress && this.maxLength > 0 && event.keyCode >= 32) {

0 commit comments

Comments
 (0)