Skip to content

Commit cfcf5c6

Browse files
tsv2013tsv2013
and
tsv2013
authored
Choice Inplace Editor allows a batch creating of more than the specified number of items (creator.maximumChoicesCount) (#6638)
* Choice Inplace Editor allows a batch creating of more than the specified number of items (`creator.maximumChoicesCount`) Fixes #6617 * Update string-editor.ts * Update string-editor.ts * Choice Inplace Editor allows a batch creating of more than the specified number of items (`creator.maximumChoicesCount`) Fixes #6617 --------- Co-authored-by: tsv2013 <tsv2013@noreply.github.com>
1 parent a7d822a commit cfcf5c6

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ export abstract class StringItemsNavigatorBase {
3434

3535
newItems.splice(startIndex, 1);
3636
itemsToAdd.forEach((item, offset) => {
37-
newItems.splice(startIndex + offset, 0, createNewItem(item));
37+
if (creator.maximumChoicesCount <= 0 || newItems.length < creator.maximumChoicesCount) {
38+
newItems.splice(startIndex + offset, 0, createNewItem(item));
39+
}
3840
});
3941
this.question[this.getItemsPropertyName(items)] = newItems;
4042
}
@@ -610,4 +612,4 @@ export class StringEditorViewModelBase extends Base {
610612
.append("svc-string-editor--multiline", !!this.locString.allowLineBreaks)
611613
.toString();
612614
}
613-
}
615+
}

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

+23
Original file line numberDiff line numberDiff line change
@@ -1050,3 +1050,26 @@ test("Test string editor inplaceEditForValues without Creator", (): any => {
10501050
expect(otherItem.locText.text).toEqual("Other changed");
10511051
expect(q0.otherText).toEqual("Other changed");
10521052
});
1053+
1054+
test("StringEditor multiline paste for selectbase questions should respect creator.maximumChoicesCount", (): any => {
1055+
const creator = new CreatorTester();
1056+
creator.maximumChoicesCount = 4;
1057+
creator.JSON = {
1058+
elements: [
1059+
{ type: "radiogroup", name: "q1", choices: ["item1", "item2"] },
1060+
]
1061+
};
1062+
const question = creator.survey.getQuestionByName("q1") as QuestionRadiogroupModel;
1063+
creator.selectElement(question);
1064+
1065+
const questionAdorner = new QuestionAdornerViewModel(
1066+
creator,
1067+
question,
1068+
<any>undefined
1069+
);
1070+
var connectorItem2 = StringEditorConnector.get(question.choices[0].locText);
1071+
1072+
connectorItem2.onTextChanging.fire(null, { value: "\na\nb\r\nc\nd\n" });
1073+
expect(question.choices.map(c => c.text)).toEqual(["a", "b", "c", "item2"]);
1074+
expect(question.choices.map(c => c.value)).toEqual(["item3", "item4", "item5", "item2"]);
1075+
});

0 commit comments

Comments
 (0)