Skip to content

Commit 5605f0c

Browse files
authored
Impossible to insert spaces to the Other input field when "textUpdateMode": "onTyping" fix #10402 (#10404)
1 parent 7e47999 commit 5605f0c

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

packages/survey-core/src/question.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2665,7 +2665,7 @@ export class Question extends SurveyElement<Question>
26652665
return this.getQuestionComment();
26662666
}
26672667
public set comment(newValue: string) {
2668-
if (!!newValue) {
2668+
if (!!newValue && newValue !== this.comment) {
26692669
const trimmedValue = newValue.toString().trim();
26702670
if (trimmedValue !== newValue) {
26712671
newValue = trimmedValue;

packages/survey-core/src/question_baseselect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1722,7 +1722,7 @@ export class QuestionSelectBase extends Question {
17221722
}
17231723
}
17241724
private onOtherValueChange(item: ItemValue, event: any): void {
1725-
this.setCommentValueCore(item, event.target.value);
1725+
this.setCommentValueCore(item, (event.target?.value || "").trim());
17261726
const val = this.getCommentValueCore(item);
17271727
if (val !== event.target.value) {
17281728
event.target.value = val || "";

packages/survey-core/tests/question_baseselecttests.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3477,6 +3477,26 @@ QUnit.test("radiogroup question showOtherItem - lost focus on empty", (assert) =
34773477
assert.strictEqual(event.target.value, "", "event.target.value is empty");
34783478
assert.equal(textArea.getTextValue(), "", "text area is empty #2");
34793479
});
3480+
QUnit.test("showOtherItem & textUpdateMode = 'onTyping' , Bug#10402", (assert) => {
3481+
const survey = new SurveyModel({
3482+
"textUpdateMode": "onTyping",
3483+
"elements": [
3484+
{
3485+
"type": "radiogroup",
3486+
"name": "q1",
3487+
"choices": ["item1", "item2"],
3488+
"showOtherItem": true
3489+
}
3490+
]
3491+
});
3492+
const q1 = <QuestionRadiogroupModel>survey.getQuestionByName("q1");
3493+
q1.clickItemHandler(q1.otherItem);
3494+
q1.getCommentTextAreaModel(q1.otherItem).onTextAreaInput({ target: { value: "abc " } });
3495+
assert.equal(q1.otherValue, "abc ", "q1.otherValue #1");
3496+
assert.equal(survey.getComment("q1"), "abc ", "survey.data #1");
3497+
q1.getCommentTextAreaModel(q1.otherItem).onTextAreaChange({ target: { value: "abc xy " } });
3498+
assert.equal(q1.otherValue, "abc xy", "q1.otherValue #2");
3499+
});
34803500
QUnit.test("radiogroup & checkbox questions and choices has comment - display value, Bug#10193", (assert) => {
34813501
const survey = new SurveyModel({
34823502
"elements": [

0 commit comments

Comments
 (0)