Quantcast
Channel: jQuery Library for SharePoint Web Services
Viewing all articles
Browse latest Browse all 6517

New Post: Using SPServices to disable a field if a user is not a member of a specified SharePoint group

$
0
0
Working in SharePoint 2010 Foundation, I'm trying to disable a field on a custom editform.aspx for users who are not members of a specific group.

So, if current user is not a member of the group "Change Control - Admins", disable the CCID field.

I found what seemed to be the solution in the SPServices codeplex discussion area, but it doesn't work as expected. Not sure what I'm missing here.

It does disable the correct field, but does not matter if current user is in the specified group or not.

If i change this:

if($(xData.responseXML).find("Group[Name='Change Control - Admins']").length != 1)

to this:

if($(xData.responseXML).find("Group[Name='Change Control - Admins']").length == 1)

...then the field does not get disabled. However, it again doesn't matter if the current user is in the specified group or not.

Any help would be much appreciated.

Here's my code:
<script language="javascript" type="text/javascript" src="/CodeLibrary/jquery-1.7.2.min.js"></script>
<script language="javascript" type="text/javascript" src="/CodeLibrary/jquery.SPServices-0.7.2.min.ssl.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function() {
var groupName;

 $().SPServices({  
      operation: "GetGroupCollectionFromUser",  
      userLoginName: $().SPServices.SPGetCurrentUser(),  
      async: false,  
      completefunc: function(xData, Status) { 
        //if current user is not a member of this group...  
        if($(xData.responseXML).find("Group[Name='Change Control - Admins']").length != 1)  
        {  
              //...disable the following fields
              $("input[Title='CCID']").prop("disabled", "disabled");
              }  
      }  
    });  
});

function PreSaveAction() {
    $("input[Title='CCID']").removeProp("disabled");
    return true;
}
</script>

Viewing all articles
Browse latest Browse all 6517

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>