Skip to content

Commit

Permalink
extract enter processing
Browse files Browse the repository at this point in the history
  • Loading branch information
novikov82 committed Aug 24, 2023
1 parent 4214d46 commit b56f1ce
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2188,6 +2188,12 @@ export class Question extends SurveyElement<Question>
this.survey.processPopupVisiblityChanged(this, popupModel, visible);
}

protected onTextKeyDownHandler(event: any) {
if (event.keyCode === 13) {
(this.survey as SurveyModel).questionEditFinishCallback(this, event);
}
}

public transformToMobileView(): void { }
public transformToDesktopView(): void { }
public needResponsiveWidth() {
Expand Down Expand Up @@ -2324,6 +2330,7 @@ function makeNameValid(str: string): string {
}
return str;
}

Serializer.addClass("question", [
{ name: "!name", onSettingValue: (obj: any, val: any): any => { return makeNameValid(val); } },
{
Expand Down
6 changes: 2 additions & 4 deletions src/question_text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,12 +437,10 @@ export class QuestionTextModel extends QuestionTextBase {
};
public onKeyDown = (event: any) => {
this.checkForUndo(event);
if(this.isInputTextUpdate) {
if (this.isInputTextUpdate) {
this._isWaitingForEnter = event.keyCode === 229;
}
if (event.keyCode === 13) {
(this.survey as SurveyModel).questionEditFinishCallback(this, event);
}
this.onTextKeyDownHandler(event);
}
public onChange = (event: any): void => {
if (event.target === settings.environment.root.activeElement) {
Expand Down
4 changes: 4 additions & 0 deletions tests/question_texttests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,3 +443,7 @@ QUnit.test("Set empty text", function(assert) {
assert.equal(q.value, " a ", "question.value #6");
assert.deepEqual(survey.data, { q1: " a " }, "survey.data #6");
});
QUnit.test("Text Question KeyHandler exists", function (assert) {
const q = new QuestionTextModel("q1");
assert.ok(q["onTextKeyDownHandler"], "we need this handler for using in Survey Creator");
});

0 comments on commit b56f1ce

Please sign in to comment.