Fork me on GitHub
2sxc 9.0 for DNN 7 to 9
Website Builder, Content Manager, App-System: free and amazing - done your way
You are here: Home  >  Docs  >  Prefill new Forms

Prefill Form for New Entity

Introduced in Version 05.05.01

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

  1. Test if the user is currently editing this
  2. Test if the title of the entity is the demo-entity (the one configured in the list-settings)
  3. If no, then just give it the default toolbar
  4. 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...
  5. ...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: 'Default.aspx?tabId=@Dnn.Tab.TabID', 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>

}

Tags for this feature

Error rendering template
2serve . 2invent . 2create is 2be.