Skip to content

Commit

Permalink
"Grid layout columns" editor: Hide the "Add" button instead of disabl…
Browse files Browse the repository at this point in the history
…ing it fix #6449
  • Loading branch information
andrewtelnov committed Feb 4, 2025
1 parent 2e505a4 commit fdefcc8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
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 @@ -134,7 +134,9 @@ export abstract class PropertyGridEditorMatrix extends PropertyGridEditor {
protected addItem(creator: ISurveyCreatorOptions, obj: Base, question: QuestionMatrixDynamicModel) {
question.addRow();
}
protected getHasAddButton(): boolean { return true; }
public onGetQuestionTitleActions(obj: Base, options: any, creator: ISurveyCreatorOptions): void {
if(!this.getHasAddButton()) return;
const question: QuestionMatrixDynamicModel = options.question;
options.titleActions.push({
id: "add-item",
Expand Down Expand Up @@ -655,7 +657,7 @@ export class PropertyGridEditorMatrixLayoutColumns extends PropertyGridEditorMat
const q = options.cellQuestion;
q.textUpdateMode = "onTyping";
}

protected getHasAddButton(): boolean { return false; }
public onCreated(obj: Base, question: Question, prop: JsonObjectProperty, options?: ISurveyCreatorOptions, propGridDefinition?: ISurveyPropertyGridDefinition) {
super.onCreated(obj, question, prop, options, propGridDefinition);
const matrixQuestion = <QuestionMatrixDynamicModel>question;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3323,6 +3323,22 @@ test("check pages editor respects onPageAdding", () => {
expect(creator.survey.pages.length).toBe(1);
settings.defaultNewSurveyJSON = savedNewJSON;
});
test("panellayoutcolumns doesn't have adding button", () => {
const creator = new CreatorTester();
creator.JSON = {
gridLayoutEnabled: true,
elements: [{ type: "text", name: "q1" }]
};
const propertyGrid = new PropertyGridModelTester(creator.survey.pages[0]);
const gridColumnsQuestion = <QuestionMatrixDynamicModel>(propertyGrid.survey.getQuestionByName("gridLayoutColumns"));
expect(gridColumnsQuestion).toBeTruthy();
expect(gridColumnsQuestion.allowAddRows).toBeFalsy();
expect(gridColumnsQuestion.getTitleToolbar()).toBeTruthy();
const helpButton = gridColumnsQuestion.titleActions.find(a => a.id === "property-grid-help");
const addButton = gridColumnsQuestion.titleActions.find(a => a.id === "add-item");
expect(helpButton).toBeTruthy();
expect(addButton).toBeFalsy();
});
test("Set property name into correct category", () => {
Serializer.addProperty("question", {
name: "validation",
Expand Down

0 comments on commit fdefcc8

Please sign in to comment.