4

I want to create sections inside edit form of my list. Example how to create a section as shown in photo: enter image description here

In this example there are two sections: Informatat baze and Employement Data. How can I achieve this using C#?

5 Answers 5

5

We 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>

enter image description here

1
  • how to add a fiv tag within the above solution?, if i wanna manipulate with something, some modifications, its not allowing me to add div tag.because its added by tr tag
    – samolpp2
    Apr 2, 2019 at 14:12
6

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

1
  • 1
    This is definitely the right way to do this. Only do it according to my way if for some reason CSR isn't capable enough.
    – Jussi Palo
    Dec 14, 2017 at 14:57
4

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.

0

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>
0

For DispForm use:

  <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-formlabel span: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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.