Sometimes you want to pre-fill a new Entity with existing information - like the current date, the users name, or data from another list like a file-ID or infos from an XML-Stream. This is now possible.
Server Side Helpers in 8.4.5
UPDATE since 2sxc 8.4.5 you can also set the prefill with the server-side Edit.Toolbar helper. This is usually much easier. Not fully documented yet, but approx. like this:
@Edit.Toolbar(actions: "new", contentType: "NewsItem", prefill = new { Category = "something" } )
Note: You should have a Sherlock-Snippet in the template editor that helps you with this.
JS Methods (older, harder way)
It is not well documented yet, here a quick demo in the current implementation. We're basically doing the following
- Test if the user is currently editing this
- Test if the title of the entity is the demo-entity (the one configured in the list-settings)
- If no, then just give it the default toolbar
- If it is the demo entity, then an edit will of course give a new record. Then assemble the toolbar the way the automatic toolbar is built...
- ...and give it a parameter "prefill=" with JSON containing keys/values
<div class="sc-element">
@if(DotNetNuke.Common.Globals.IsEditMode())
{
if(Content.Title != "Demo Feature")
{
@*currently not showing the demo-entity, so show the normal toolbar*@
@Html.Raw(Content.Toolbar)
}
else
{
@*currently showing the demo-entity, so show the prefill-edit-button*@
<ul class="sc-menu-deactivated">
<li>
<a class="sc-menu-edit" href="javascript: $2sxc.beta.OpenDialog('new', { moduleId: @Dnn.Module.ModuleID, tabId: @Dnn.Tab.TabID, contentGroupId: @List.First().GroupId, sortOrder: 0, returnUrl: '[email protected]', prefill: { DocumentedOnPage: 'Page:@Dnn.Tab.TabID', Title: '@Dnn.Tab.Title' }}); ">create for this page <img src="/DesktopModules/ToSIC_SexyContent/Images/Edit.png" /></a>
</li>
</ul>
}
}
more stuff here...</div>
Here the List-version:
@foreach(var Element in List)
{
var Content = Element.Content;
<h1 class="sc-element" onclick="$2sxc.beta.OpenDialog('new', { moduleId: @Dnn.Module.ModuleID, tabId: @Dnn.Tab.TabID, contentGroupId: @Element.GroupId, sortOrder: @Element.SortOrder, prefill: { Name: 'Person ' + new Date() }});">
@Html.Raw(Content.Toolbar)
@Content.Name
</h1>
}