diff --git a/packages/survey-creator-core/src/property-grid/condition.ts b/packages/survey-creator-core/src/property-grid/condition.ts index c1174141cc..032a10b4f0 100644 --- a/packages/survey-creator-core/src/property-grid/condition.ts +++ b/packages/survey-creator-core/src/property-grid/condition.ts @@ -38,10 +38,22 @@ export class PropertyGridEditorCondition extends PropertyGridEditorExpression { ): any { return { type: "comment", - showOptionsCaption: false, - readOnly: options.allowEditExpressionsInTextEditor === false + showOptionsCaption: false }; } + public canClearPropertyValue(obj: Base, prop: JsonObjectProperty, question: Question, options: ISurveyCreatorOptions): boolean { + return options.allowEditExpressionsInTextEditor !== false; + } + public onSetup(obj: Base, question: Question, prop: JsonObjectProperty, options: ISurveyCreatorOptions) { + if(options.allowEditExpressionsInTextEditor === false) { + question.onKeyDownPreprocess = (event: any) => { + const allowed = ["Tab", "ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight", "Home", "End"]; + if (!event.ctrlKey && allowed.indexOf(event.key) < 0) { + event.preventDefault(); + } + }; + } + } public createPropertyEditorSetup( obj: Base, prop: JsonObjectProperty, diff --git a/packages/survey-creator-core/src/property-grid/index.ts b/packages/survey-creator-core/src/property-grid/index.ts index 194c577bad..ab29ba60bc 100644 --- a/packages/survey-creator-core/src/property-grid/index.ts +++ b/packages/survey-creator-core/src/property-grid/index.ts @@ -356,15 +356,8 @@ export class PropertyGridTitleActionsCreator { } if ((question).allowBatchEdit !== false) { if (!!editor.createPropertyEditorSetup) { - if (enabled) { - enabled = - !editor.isPropertyEditorSetupEnabled || - editor.isPropertyEditorSetupEnabled( - this.obj, - property, - options.question, - this.options - ); + if (!!editor.isPropertyEditorSetupEnabled) { + enabled = editor.isPropertyEditorSetupEnabled(this.obj, property, options.question, this.options); } actions.push( this.createEditorSetupAction(editor, property, question, enabled) diff --git a/packages/survey-creator-core/tests/property-grid/property-grid.tests.ts b/packages/survey-creator-core/tests/property-grid/property-grid.tests.ts index e5303fa6d6..018060b4ed 100644 --- a/packages/survey-creator-core/tests/property-grid/property-grid.tests.ts +++ b/packages/survey-creator-core/tests/property-grid/property-grid.tests.ts @@ -628,25 +628,29 @@ test("Show property editor for condition/expression", () => { ).toBeTruthy(); //defaultValueExpression is here }); test("Test options.allowEditExpressionsInTextEditor", () => { - var question = new QuestionTextModel("q1"); - var options = new EmptySurveyCreatorOptions(); + const question = new QuestionTextModel("q1"); + question.visibleIf = "{q2} = 'abc'"; + const options = new EmptySurveyCreatorOptions(); options.allowEditExpressionsInTextEditor = false; var propertyGrid = new PropertyGridModelTester(question, options); - var conditionQuestion = propertyGrid.survey.getQuestionByName("visibleIf"); - var expressionQuestion = propertyGrid.survey.getQuestionByName( - "defaultValueExpression" - ); - expect(conditionQuestion.isReadOnly).toBeTruthy(); - expect(expressionQuestion.isReadOnly).toBeFalsy(); + var conditionQuestion = propertyGrid.survey.getQuestionByName("visibleIf"); + var expressionQuestion = propertyGrid.survey.getQuestionByName("defaultValueExpression"); + expect(conditionQuestion.onKeyDownPreprocess).toBeTruthy(); + expect(expressionQuestion.onKeyDownPreprocess).toBeFalsy(); + expect(conditionQuestion.getTitleToolbar()).toBeTruthy(); + expect(conditionQuestion.titleActions).toHaveLength(2); + expect(conditionQuestion.titleActions[1].enabled).toBeTruthy(); options.allowEditExpressionsInTextEditor = true; propertyGrid = new PropertyGridModelTester(question, options); - conditionQuestion = propertyGrid.survey.getQuestionByName("visibleIf"); - expressionQuestion = propertyGrid.survey.getQuestionByName( - "defaultValueExpression" - ); - expect(conditionQuestion.isReadOnly).toBeFalsy(); - expect(expressionQuestion.isReadOnly).toBeFalsy(); + conditionQuestion = propertyGrid.survey.getQuestionByName("visibleIf"); + expressionQuestion = propertyGrid.survey.getQuestionByName("defaultValueExpression"); + expect(conditionQuestion.onKeyDownPreprocess).toBeFalsy(); + expect(expressionQuestion.onKeyDownPreprocess).toBeFalsy(); + expect(conditionQuestion.getTitleToolbar()).toBeTruthy(); + expect(conditionQuestion.titleActions).toHaveLength(3); + expect(conditionQuestion.titleActions[1].enabled).toBeTruthy(); + expect(conditionQuestion.titleActions[2].enabled).toBeTruthy(); }); test("Support question property editor", () => {