Skip to content

Commit

Permalink
#6338 - fix onGetPropertyReadOnly
Browse files Browse the repository at this point in the history
  • Loading branch information
novikov82 committed Jan 9, 2025
1 parent d63f652 commit d57af65
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
15 changes: 11 additions & 4 deletions packages/survey-creator-core/src/creator-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ import {
PageAddingEvent, DragStartEndEvent,
ElementGetExpandCollapseStateEvent,
ElementGetExpandCollapseStateEventReason,
PropertyAddingEvent
PropertyAddingEvent,
GetPropertyReadOnlyEvent
} from "./creator-events-api";
import { ExpandCollapseManager } from "./expand-collapse-manager";
import designTabSurveyThemeJSON from "./designTabSurveyThemeJSON";
Expand Down Expand Up @@ -451,7 +452,11 @@ export class SurveyCreatorModel extends Base
/**
* An event that is raised when Survey Creator sets the read-only status for a survey element property. Use this event to change the read-only status for individual properties.
*/
public onGetPropertyReadOnly: EventBase<SurveyCreatorModel, PropertyGetReadOnlyEvent> = this.addCreatorEvent<SurveyCreatorModel, PropertyGetReadOnlyEvent>();
public onPropertyGetReadOnly: EventBase<SurveyCreatorModel, PropertyGetReadOnlyEvent> = this.addCreatorEvent<SurveyCreatorModel, PropertyGetReadOnlyEvent>();
/**
* Obsolete
*/
public onGetPropertyReadOnly: EventBase<SurveyCreatorModel, GetPropertyReadOnlyEvent> = this.onPropertyGetReadOnly;

/**
* An event that is raised when Survey Creator [instantiates a survey to display a UI element](https://surveyjs.io/survey-creator/documentation/creator-v2-whats-new#survey-creator-ui-elements-are-surveys). Handle this event to customize the UI element by modifying the survey.
Expand Down Expand Up @@ -1737,16 +1742,18 @@ export class SurveyCreatorModel extends Base
creatorReadOnly = this.readOnly;
}
const proposedValue = creatorReadOnly || readOnly;
if (this.onGetPropertyReadOnly.isEmpty) return proposedValue;
if (this.onPropertyGetReadOnly.isEmpty) return proposedValue;
const options = {
obj: obj,
element: obj,
property: property,
readOnly: proposedValue,
propertyName: property.name,
parentObj: parentObj,
parentElement: parentObj,
parentProperty: parentProperty
};
this.onGetPropertyReadOnly.fire(this, options);
this.onPropertyGetReadOnly.fire(this, options);
return options.readOnly;
}

Expand Down
21 changes: 14 additions & 7 deletions packages/survey-creator-core/src/creator-events-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface ElementDeletingEvent {
allowing: boolean;
}

export interface PropertyGetReadOnlyEvent {
export interface GetPropertyReadOnlyEvent {
/**
* A property whose read-only status you can change.
*/
Expand All @@ -30,17 +30,24 @@ export interface PropertyGetReadOnlyEvent {
*/
parentProperty: JsonObjectProperty;
/**
* A survey element (question, panel, page, or the survey itself) for which you can change the read-only status.
* Obsolete
*/
obj: Base;
obj?: Base;
/**
* A survey element that contains `options.parentProperty`. `options.parentObj` has a value only for nested properties.
* Obsolete
*/
parentObj?: Base;
readOnly: boolean;
}
export interface PropertyGetReadOnlyEvent extends GetPropertyReadOnlyEvent {
/**
* A survey element (question, panel, page, or the survey itself) for which you can change the read-only status.
*/
parentObj: Base;
element: Base;
/**
* A Boolean value that specifies the property's read-only status.
* A survey element that contains `options.parentProperty`. `options.parentObj` has a value only for nested properties.
*/
readOnly: boolean;
parentElement: Base;
}

export interface ElementGetDisplayNameEvent {
Expand Down
2 changes: 1 addition & 1 deletion packages/survey-creator-core/tests/creator-base.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4570,7 +4570,7 @@ test("New ghost page shouldn't be created if onPageAdding sets allow to false",
});
test("Do not raise error on undefined property in onIsPropertyReadOnlyCallback", (): any => {
const creator = new CreatorTester();
creator.onGetPropertyReadOnly.add((_, options) => { });
creator.onPropertyGetReadOnly.add((_, options) => { });
let counter = 0;
expect(creator.onIsPropertyReadOnlyCallback(creator.survey, undefined, false, undefined, undefined)).toBeFalsy();
});
Expand Down

0 comments on commit d57af65

Please sign in to comment.