In one of the requirements I had to create a Share Point Hosted App, create a custom form and attach it to the list. This is fairly straightforward and involves editing the list schema.xml. Let’s see the steps involved.
Default New Form would look plain like below.
Let’s create a new custom form,
Add a new aspx page to the list.
Open the newly added page. It would be as below,
Remove<WebPartPages:WebPartZonerunat="server"FrameType="TitleBarOnly"ID="full"Title="loc:full"/> from Placeholder Main section and add Field label, Field description and Form field as per need. The Field Name is the internal name of the column. Control Mode specifies whether the form Mode is New/Edit/Display.
I will be placing the fields within a div inside a table to give a tabular look and feel.
- <div>
- <SharePoint:FieldLabel runat="server" FieldName="EmployeeName" ControlMode="New" />
- <SharePoint:FieldDescription runat="server" FieldName="EmployeeName" ControlMode="New" />
- <SharePoint:FormField runat="server" FieldName="EmployeeName" ControlMode="New" />
- </div>
<SharePoint:SaveButton ID="SaveButton1" runat="server" ControlMode="New" ></SharePoint:SaveButton>
<SharePoint:GoBackButton ID="GoBackButton1" runat="server" ControlMode="New"></SharePoint:GoBackButton>
As you can see the ControlMode attribute is set to New. This is because it is a new form we are creating. For editing and displaying forms the control mode value will be Edit and Display respectively.
Now let’s attach the new form to the SharePoint list. Go to the schema.xml of the list figure out the content within the <Forms></Forms> tag which will be usually towards the end of the file.
Replace the NewForm tag with the below line.
- <Form Type="NewForm" Url="NewEmployee.aspx" Path="NewEmployee.aspx" WebPartZoneID="Main"Template="NewEmployee.aspx" />
The updated schema looks like below:
If we are attaching custom edit and display forms change the corresponding Form Tags accordingly.
Now once the customization is done, let go to the custom page’s properties (Press F4) and change the deployment type to Element File.
Deploy the app and click on Trust It.
Click on new Item to create an item with the custom form.
Now you can see that the custom form has been successfully deployed along with the app. On clicking New it picks up the Custom Form and not the OOTB one,
Currenlly no CSS has been applied . If any CSS or javascript needs to be added to this custom form we can add it within the custom aspx mark up inside the PlaceHolderAdditionalPageHead section.
The CSS can be referred as:
- <link rel="Stylesheet"type="text/css"href="../../Content/App.css"/>
- <script type="text/javascript" src="../../Content/CustomJS.js"></script>
------------------------------------------------------------------------------------------------------------------------------
Source: http://www.c-sharpcorner.com/article/add-custom-new-edit-display-form-to-list-using-sharepoint-ho/
No comments:
Post a Comment