Skip to content

Commit 8ffa6ed

Browse files
authored
#6653 Inplace Editor - A line break character \n appears when removing the title or description (#6655)
Fixes #6653
1 parent 1e0a326 commit 8ffa6ed

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
@@ -1051,6 +1051,40 @@ test("Test string editor inplaceEditForValues without Creator", (): any => {
10511051
expect(q0.otherText).toEqual("Other changed");
10521052
});
10531053

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

0 commit comments

Comments
 (0)