Hello
As you can see if the SchedulerDemo (also included in jQueryDemo_V2), we have a custom frame to be able to edit the two custom fields: customfield1 and customfield2. These are part of a json object - AEventItem.UserData that can store any json structure you like.
The event OnEventToSchedulerFrameControls (= SchedulerEventToSchedulerFrameControls handler in the demo), is called when the editor is going to be displayed to the user, for a new or existing event.
In the event handler, we will fill the controls with the user data, and we can also initialize the custom fields.
- Code: Select all
UserDataObj:= SO(AEventItem.UserData);
if Assigned(UserDataObj) then
begin
if UserDataObj.DataType = stNull then // new event
begin
UserDataObj.S['customfield1']:= 'Default data';
end;
MyFrame.edCustomField1.Text:= UserDataObj.S['customfield1'];
MyFrame.edCustomField2.Text:= UserDataObj.S['customfield2'];
end;
UserDataObj is a json object, you can add any fields and field types you like, including nested objects, for instance:
- Code: Select all
UserDataObj.I['customintegerfield']:= 1234;
UserDataObj.B['custombooleanfield']:=True;
NestedObject:= SO();
NestedObject.S['someprop']:= 'somevalue';
UserDataObj.O['customobjfield'']:= NestedObject;
Then in the event OnSchedulerFrameControlsToEvent (= SchedulerSchedulerFrameControlsToEvent handler in the demo)
that is called when the event is created (or edited) we assign the custom fields, using the code
- Code: Select all
UserDataObj:= SO();
UserDataObj.S['customfield1']:= MyFrame.edCustomField1.Text;
UserDataObj.S['customfield2']:= MyFrame.edCustomField2.Text;
AEventItem.UserData:= UserDataObj.AsJSon;