Disable SharePoint control based upon membership

Keep in mind that this does not validate group membership on the server. It's client-side only. Meaning... if you have a public facing site and are concerned about malicious actors, use another solution.

  1. Create a new form
  2. Find the row with the control you want to disable and add an ID:
					<tr id="status-row">
						<td width="190px" valign="top" class="ms-formlabel">
							<H3 class="ms-standardheader">
								<nobr>Status<span class="ms-formvalidation"> *</span>
								</nobr>
							</H3>
						</td>
						<td width="400px" valign="top" class="ms-formbody">
							<SharePoint:FormField runat="server" id="ff6{$Pos}" ControlMode="Edit" FieldName="Status" __designer:bind="{ddwrt:DataBind('u',concat('ff6',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Status')}"/>
							<SharePoint:FieldDescription runat="server" id="ff6description{$Pos}" FieldName="Status" ControlMode="Edit"/>
						</td>
					</tr>
  1. Use the following script:
  var statusRow = document.querySelector('#status-row');
  var combo = statusRow.children[1].children[0].children[0];
  combo.disabled = true;
  sprLib.user({baseUrl:'/'}).groups().then(function(groups){
      for(var i = 0; i &lt; groups.length; i++){
          var title = groups[i].Title;
          if(title === 'Members' || title === 'Owners'){
              combo.disabled = false;
          }
      }

  });
                    

A few comments. This code has a dependency on sprestlib by @gitbrent which calls the rest API in the background. If you need IE support you will need a Promise pollyfill to make it work.

You may also like

  • AngularJS 와 VueJS 반응성

    VueJS는 우리가 가지고 있는 자바스크립트 프레임워크의 생태계에서 비교적 새로운 라이브러리다. 여윈반면 JS는 오랫동안 자리를 잡았고 많은 후원을 받고 있다. 그러나 한 개발자의 MV* 라이브러리는 흥미로운 대안일 수 있다.

    Read More >
  • SharePoint 2010, REST, AngularJS

    Sometimes you need a more dynamic means of changing things on a form in SharePoint. Sometimes you need to create an interface that is less "SharePoint-y". Using REST in conjunction with a library like AngularJS might be the route to go in these situations.

    Read More >