none
Add custom field to wiki page in edit mode

    Question

  • Hi

    I am looking for a way to add a custom field to the page layout of an enterprise wiki page, but only in edit mode.

    I found this on how to determine if the page is in edit mode. So I would try to add the field to the page layout and hide it unless in edit mode.

    Can you point me in the right direction or tell me that this approach is not a good idea.

    TIA
    Alex

    Thursday, April 06, 2017 8:28 PM

Answers

  • Oh, actually it was easy. I just added the field inside the edit panel in edit mode. Style is not yet nice, but it works.

    <PublishingWebControls:EditModePanel class="ewiki-margin" runat="server">
            <div class="ms-descriptiontext">
    	        <b class="ewiki-pagename-align"><SharePoint:FieldLabel FieldName="FileLeafRef" runat="server"/></b>
    		<SharePoint:FileField id="PageNameInEditMode" CssClass="ewiki-pagename-align" FieldName="FileLeafRef" DisableInputFieldLabel="true" runat="server"/>
    		<SharePoint:FormField id="editPageStatusFieldCtrl" ControlMode="Edit" FieldName="PageStatus" runat="server"/>
    	</div>
    </PublishingWebControls:EditModePanel>
    

    • Marked as answer by Alex Vary Tuesday, May 30, 2017 3:37 PM
    Thursday, April 06, 2017 9:09 PM

All replies

  • Hi Alex- could you provide more details on what type of "field" this is, what it's for and why it's so important to hide it? I'm not looking for "secret" details, just a better understanding. I'm thinking there's a much better way to go about this, but that depends on your answer.

    cameron rautmann

    Thursday, April 06, 2017 8:50 PM
  • Hi Cameron,

    It is a choice field called status. It has the values of Draft and Published. I use it to show to users an indication if an article is fully ready or still being worked on. I realize that I could force check-out and publishing.

    Out of the box a user would have to go to the pages library open the properties of the page and set the value there. But this is too complicated. I want to put this dropdown field right of the box that allows you to change the page url. So when you are done editing you would just set it to published and save the page.

    Thursday, April 06, 2017 8:57 PM
  • Oh, actually it was easy. I just added the field inside the edit panel in edit mode. Style is not yet nice, but it works.

    <PublishingWebControls:EditModePanel class="ewiki-margin" runat="server">
            <div class="ms-descriptiontext">
    	        <b class="ewiki-pagename-align"><SharePoint:FieldLabel FieldName="FileLeafRef" runat="server"/></b>
    		<SharePoint:FileField id="PageNameInEditMode" CssClass="ewiki-pagename-align" FieldName="FileLeafRef" DisableInputFieldLabel="true" runat="server"/>
    		<SharePoint:FormField id="editPageStatusFieldCtrl" ControlMode="Edit" FieldName="PageStatus" runat="server"/>
    	</div>
    </PublishingWebControls:EditModePanel>
    

    • Marked as answer by Alex Vary Tuesday, May 30, 2017 3:37 PM
    Thursday, April 06, 2017 9:09 PM
  • 
    
    var inDesignMode = document.forms[MSOWebPartPageFormName].MSOLayout_InDesignMode.value;
    
    if (inDesignMode == "1")
    {
        // page is in edit mode
    }
    else
    {
        // page is in browse mode
    }
    //This will refer to value of the following html input control, which is rendering on the page when it is in edit mode:
    
    <input type="hidden" name="MSOLayout_InDesignMode" id="MSOLayout_InDesignMode" value="1" />
    Update: for wiki pages, you will need _wikiPageMode parameter:
    
    var wikiInEditMode = document.forms[MSOWebPartPageFormName]._wikiPageMode.value;
    if (wikiInEditMode == "Edit")
    {
        // wiki page is in edit mode
    }
    else
    {
        // wiki page is not in edit mode
    }


    Thanks, Amit Kumar, LinkedIn Profile ** My Blog


    Friday, April 07, 2017 9:57 AM