0

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?

  • 1
    could u check with prop attribute as like prop("disabled", true) – Md. Tahmidul Abedin Feb 14 '18 at 22:07
  • "prop" instead of "attr" was part one of the solution, as you can see below. thank you. – DanJ Feb 16 '18 at 16:19
1

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");
        }
    }
}
  • Logically, it seems like this would work. It makes sense. However, the DDL is still enabled with no change when I include this in the code. I can't figure out what's going wrong. – DanJ Feb 15 '18 at 18:46
  • 1
    Are you sure the jquery selector for the DDL is working? The select tag isn't actually an input, so maybe try: $("select[Title='Approval Status']").prop("disabled", "disabled"); – GVIrish Feb 16 '18 at 14:35
  • In retrospect, I should have seen that. But I'm glad you did. Thanks! That did the trick! – DanJ Feb 16 '18 at 16:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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