I am using Nested Content and I want to set 2 of the fields ("Entered By" and "Entered Date") to a default value if not entered by the user.
I have been trying to figure out the code to go in "ContentService.Saving" but am not doing very well!!
I initially thought about converting he IContent to an IPublishedContent but that doesn't seem possible / straightforward. I then started to look at getting the raw content (JSON, I assume), updating that and then putting it back. That might be the solution but I'm struggling to figure out the code / process.
Any suggestions / pointers / template code would be most welcome!
Setting default values can be done in the EditorModelEventManager.SendingContentModel event (see documentation), but that works on a content level, not for the dynamically added Nested Content elements...
The NC data is stored as JSON, so you could use the ContentService.Saving event to parse the data and set the default values within it... Not a nice way (especially if you see what's required to parse the data) and you can't use client-side validation, e.g. required properties (as it's validated before saving).
So for now, there doesn't seem to be a good solution. I would opt for adding default values to all property editors, so it's just part of configuring the data type.
Default values for Nested Content fields
I am using Nested Content and I want to set 2 of the fields ("Entered By" and "Entered Date") to a default value if not entered by the user.
I have been trying to figure out the code to go in "ContentService.Saving" but am not doing very well!!
I initially thought about converting he IContent to an IPublishedContent but that doesn't seem possible / straightforward. I then started to look at getting the raw content (JSON, I assume), updating that and then putting it back. That might be the solution but I'm struggling to figure out the code / process.
Any suggestions / pointers / template code would be most welcome!
Setting default values can be done in the
EditorModelEventManager.SendingContentModel
event (see documentation), but that works on a content level, not for the dynamically added Nested Content elements...The NC data is stored as JSON, so you could use the
ContentService.Saving
event to parse the data and set the default values within it... Not a nice way (especially if you see what's required to parse the data) and you can't use client-side validation, e.g. required properties (as it's validated before saving).So for now, there doesn't seem to be a good solution. I would opt for adding default values to all property editors, so it's just part of configuring the data type.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.