Question

With help from here, I've successfully made some of the fields in my SP forms read-only (disabled). However, it seems the same method does not apply for drop-down lists. I have a drop down list I need to disable based on the users' permissions. I'm using the IsCurrentUserMemberOfGroup function to check if the user is a member of certain groups. Here's what I'm using`

    IsCurrentUserMemberOfGroup("Members", function (isCurrentUserInGroup) {
if(isCurrentUserInGroup)
{
     $(document).ready(function()

{

$("input[title='Approval Status']").attr("readonly","true").css('background-color','#F6F6F6');

I've tried this, too...

$("input[Title='Approval Status']").attr("disabled", "disabled");

Neither of which successfully disables the ddl. What am I missing? What do I need to do?

Was it helpful?

Solution

Two suggestions that may help:

Use jQuery's prop function:

$("select[Title='Approval Status']").prop("disabled", "disabled");

And instead of using jQuery's document.ready, use SharePoint's ExecuteOrDelayUntilScriptLoaded. The reason for this is that sometimes sp.js isn't finished with setting all the controls and values on the page before document.ready fires. It would look something like this:

ExecuteOrDelayUntilScriptLoaded(UserCheck,"sp.js");

function UserCheck() {
    IsCurrentUserMemberOfGroup("Members", function (isCurrentUserInGroup) {
        if(isCurrentUserInGroup) {
            $("input[Title='Approval Status']").prop("disabled", "disabled");
        }
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top