Skip to content

Commit c764b9e

Browse files
committed
#6653 Inplace Editor - A line break character \n appears when removing the title or description (#6655)
Fixes #6653
1 parent 1f5c024 commit c764b9e

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

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

+7-6
Original file line numberDiff line numberDiff line change
@@ -422,9 +422,8 @@ export class StringEditorViewModelBase extends Base {
422422
private getClearedText(target: HTMLElement): string {
423423
const html = target.innerHTML;
424424
const text = target.innerText;
425-
if(!this.creator) return this.locString.hasHtml ? html : text;
426425
let mdText = null;
427-
if (!this.editAsText) {
426+
if (!this.editAsText && this.creator) {
428427
const options = {
429428
element: <Base><any>this.locString.owner,
430429
text: <any>null,
@@ -438,9 +437,11 @@ export class StringEditorViewModelBase extends Base {
438437
if (mdText) {
439438
clearedText = mdText;
440439
} else {
441-
let txt = this.locString.hasHtml && !this.editAsText ? html : text;
442-
if (!this.locString.allowLineBreaks) txt = clearNewLines(txt);
443-
clearedText = txt;
440+
clearedText = this.locString.hasHtml && !this.editAsText ? html : text;
441+
const txt = clearNewLines(clearedText);
442+
if (!this.locString.allowLineBreaks || !txt) {
443+
clearedText = txt;
444+
}
444445
}
445446
const owner = this.locString.owner as any;
446447

@@ -451,7 +452,7 @@ export class StringEditorViewModelBase extends Base {
451452
newValue: clearedText,
452453
doValidation: false
453454
};
454-
this.creator.onValueChangingCallback(changingOptions);
455+
if (this.creator) this.creator.onValueChangingCallback(changingOptions);
455456
return changingOptions.newValue;
456457
}
457458
private getErrorTextOnChanged(clearedText: string): string {

packages/survey-creator-core/tests/string-editor.tests.ts

+34
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,40 @@ test("Test string editor inplaceEditForValues without Creator", (): any => {
10421042
expect(q0.otherText).toEqual("Other changed");
10431043
});
10441044

1045+
test("Test string editor description clear (with EOL)", (): any => {
1046+
const survey = new SurveyModel({
1047+
"pages": [
1048+
{
1049+
"name": "page1",
1050+
"elements": [
1051+
{
1052+
"type": "radiogroup",
1053+
"title": "title",
1054+
"description": "desc",
1055+
"name": "q0",
1056+
"choices": ["i1", "i2"]
1057+
}
1058+
]
1059+
}
1060+
]
1061+
});
1062+
1063+
const q0 = survey.getQuestionByName("q0");
1064+
const itemValue = q0.choices[0];
1065+
var seChoice = new StringEditorViewModelBase(itemValue.locText);
1066+
var seDescription = new StringEditorViewModelBase(q0.locDescription);
1067+
expect(itemValue.text).toEqual("i1");
1068+
seChoice.onBlur({ target: { innerText: "new\nTitle", innerHTML: "new\nTitle", setAttribute: () => { }, removeAttribute: () => { } } });
1069+
expect(itemValue.text).toEqual("newTitle");
1070+
1071+
expect(q0.description).toEqual("desc");
1072+
seDescription.onBlur({ target: { innerText: "new\nDesc", innerHTML: "new\nDesc", setAttribute: () => { }, removeAttribute: () => { } } });
1073+
expect(q0.locDescription.text).toEqual("new\nDesc");
1074+
1075+
seDescription.onBlur({ target: { innerText: "\n", innerHTML: "\n", setAttribute: () => { }, removeAttribute: () => { } } });
1076+
expect(q0.locDescription.text).toEqual("");
1077+
});
1078+
10451079
test("StringEditor multiline paste for selectbase questions should respect creator.maximumChoicesCount", (): any => {
10461080
const creator = new CreatorTester();
10471081
creator.maximumChoicesCount = 4;

0 commit comments

Comments
 (0)