I want to create sections inside edit form of my list. Example how to create a section as shown in photo:
In this example there are two sections: Informatat baze
and Employement Data
.
How can I achieve this using C#?
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It only takes a minute to sign up.
Sign up to join this communityWe can use jQuery to achieve it, modify the code below and add it to a Script Editor Web Part in the edit form page.
<script src="//code.jquery.com/jquery-3.2.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
//set section text and field name
AddSectionBeforeField("Informatat baze","Last Name");
AddSectionBeforeField("Employment Data","Company");
});
function AddSectionBeforeField(sectionText,fieldName){
var $fieldTR=$(".ms-standardheader nobr:contains('"+fieldName+"')").closest("tr");
$fieldTR.before("<tr style='background-color:gainsboro'><td colspan='2' class='ms-formbody' style='padding:0'><div style='font-size:16px;font-weight:bold;'>"+sectionText+"</div></td></tr>");
}
</script>
You can use SharePoint's Client Side Rendering (CSR) to customize the look and feel for SharePoint List Forms and Views. Standard mode CSR is best suited for your requirement. Please refer below link for more details.
https://www.codeproject.com/Articles/610259/SharePoint-Client-Side-Rendering-List-Forms
Using SharePoint Designer, create new Edit form for the list, and set it as default. Then edit the EditForm.aspx, break the existing one table with ROW per field into two tables. Then perhaps surround the two tables with DIVs and add required HTML to show the title, as well as border.
How can we get the below script to work on the DispForm.aspx? It works fine on the New and Edit Form pages, but not on the Display Form page.
<script src="//code.jquery.com/jquery-3.2.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
//set section text and field name
AddSectionBeforeField("Informatat baze","Last Name");
AddSectionBeforeField("Employment Data","Company");
});
function AddSectionBeforeField(sectionText,fieldName){
var $fieldTR=$(".ms-standardheader nobr:contains('"+fieldName+"')").closest("tr");
$fieldTR.before("<tr style='background-color:gainsboro'><td colspan='2' class='ms-formbody' style='padding:0'><div style='font-size:16px;font-weight:bold;'>"+sectionText+"</div></td></tr>");
}
</script>