Friday, February 21, 2014

Set field as read only on editform/newform during list provisioning

Using SharePoint 2013/2010;

Requirement: Set a Text field 'Application Name' in a list as read only on edit form page load. The list is created during site provisioning.

Solution: Customize the editform of the list by adding a content editor web part and JavaScript to make the field as read only.Add the following code in list's schema.xml file

<Form Type="EditForm" Url="EditForm.aspx" Path="CustomEditForm.aspx" WebPartZoneID="Main" UseDefaultListFormWebPart="False" >
          <AllUsersWebPart WebPartZoneID="Main" WebPartOrder="1">
              <WebPart xmlns="">
              <Assembly>Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>                      
          <AllUsersWebPart WebPartZoneID="Main" WebPartOrder="2">
        <WebPart xmlns:xsi="" xmlns:xsd="" xmlns="">
        <Title>Web part title</Title>
        <Description>Web part description</Description>
        <Assembly>Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
        <ContentLink xmlns="" />
        <Content xmlns="">
       var prev_handler = window.onload;
            this.window.onload = function () {
               if (prev_handler) {

      var lists = document.getElementsByTagName('input');
        for ( var i = 0; i &lt; lists.length; i++) {
              if (lists[i].getAttribute('title') === 'Application Name' ) {
                lists[i].readOnly = true;
            <PartStorage xmlns="" />


PS. The script need to be updated based on the field name

No comments:

Post a Comment