Skip to content

Commit

Permalink
#3644 The onSetPropertyEditorOptions - options.showTextView option do…
Browse files Browse the repository at this point in the history
…esn't hide but disables the Fast Entry editor (#3678)

* #3644 The onSetPropertyEditorOptions - options.showTextView option doesn't hide but disables the Fast Entry editor
Fixes #3644

* #3644 The onSetPropertyEditorOptions - options.showTextView option doesn't hide but disables the Fast Entry editor
Fixes #3644

* #3644 - change doc
  • Loading branch information
novikov82 authored Nov 21, 2022
1 parent 113094b commit f5e03db
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/survey-creator-core/src/creator-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ export class CreatorBase extends Base
*- options.editorOptions options that can be changed.
*- options.editorOptions.allowAddRemoveItems a boolean property, true by default. Set it false to disable add/remove items in array properties. For example 'choices', 'columns', 'rows'.
*- options.editorOptions.allowRemoveAllItems a boolean property, true by default. Set it false to disable remove all items in array properties. For example 'choices', 'columns', 'rows'.
*- options.editorOptions.showTextView a boolean property, true by default. Set it false to disable "Manual Entry" tab for "choices" property.
*- options.editorOptions.allowBatchEdit a boolean property, true by default. Set it false to hide the "Edit" button for the "choices" property.
*- options.editorOptions.itemsEntryType a string property, 'form' by default. Set it 'fast' to show "Manual Entry" tab for "choices" property by default.
*/
public onSetPropertyEditorOptions: Survey.Event<
Expand Down
28 changes: 15 additions & 13 deletions packages/survey-creator-core/src/property-grid/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,20 +321,22 @@ export class PropertyGridTitleActionsCreator {
this.createClearValueAction(editor, property, question, enabled)
);
}
if (!!editor.createPropertyEditorSetup) {
if (enabled) {
enabled =
!editor.isPropertyEditorSetupEnabled ||
editor.isPropertyEditorSetupEnabled(
this.obj,
property,
options.question,
this.options
);
if ((<any>question).allowBatchEdit !== false) {
if (!!editor.createPropertyEditorSetup) {
if (enabled) {
enabled =
!editor.isPropertyEditorSetupEnabled ||
editor.isPropertyEditorSetupEnabled(
this.obj,
property,
options.question,
this.options
);
}
actions.push(
this.createEditorSetupAction(editor, property, question, enabled)
);
}
actions.push(
this.createEditorSetupAction(editor, property, question, enabled)
);
}
var helpAction = this.createPropertyHelpAction(question);
if (!!helpAction) {
Expand Down
4 changes: 3 additions & 1 deletion packages/survey-creator-core/src/property-grid/matrices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,8 @@ export abstract class PropertyGridEditorMatrix extends PropertyGridEditor {
var evtOptions = {
allowAddRemoveItems: true,
allowRemoveAllItems: true,
showTextView: true
showTextView: true,
allowBatchEdit: true
// options.itemsEntryType
};
options.onSetPropertyEditorOptionsCallback(prop.name, <any>obj, evtOptions);
Expand All @@ -411,6 +412,7 @@ export abstract class PropertyGridEditorMatrix extends PropertyGridEditor {
}
(<any>matrix).allowRemoveAllItems = evtOptions.allowRemoveAllItems;
(<any>matrix).showTextView = evtOptions.showTextView;
(<any>matrix).allowBatchEdit = evtOptions.allowBatchEdit;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1542,10 +1542,39 @@ test("options.onSetPropertyEditorOptionsCallback", () => {
const actions = choicesQuestion.getTitleActions();
expect(actions).toHaveLength(2);
const updater = getAddItemActionEnableUpdater(choicesQuestion);
expect(actions[0].id).toEqual("property-grid-setup");
expect(actions[0].enabled).toBeFalsy();
expect(updater()).toBeFalsy();
});

test("options.onSetPropertyEditorOptionsCallback - allowBatchEdit", () => {
const options = new EmptySurveyCreatorOptions();
var propName = "";
var object = null;
options.onSetPropertyEditorOptionsCallback = (
propertyName: string,
obj: Base,
options: any
) => {
if (propertyName != "choices") return;
propName = propertyName;
object = obj;
options.allowBatchEdit = false;
};

const question = new QuestionDropdownModel("q1");
question.choices = [1, 2, 3];
const propertyGrid = new PropertyGridModelTester(question, options);
const choicesQuestion = <QuestionMatrixDynamicModel>(
propertyGrid.survey.getQuestionByName("choices")
);
expect(propName).toEqual("choices");
const actions = choicesQuestion.getTitleActions();
expect(actions).toHaveLength(2);
expect(actions[0].id).toEqual("property-grid-clear");
expect(actions[1].id).toEqual("add-item");
});

test("options.onValueChangingCallback", () => {
var options = new EmptySurveyCreatorOptions();
options.onValueChangingCallback = (options: any) => {
Expand Down

0 comments on commit f5e03db

Please sign in to comment.