Page 1 of 1

How To Disable Option List Items

Posted: 2022-11-04 08:37
by rngoda
Hi, Apgineers, I do not know if any has ever been in a situation where they wish to disable option list items. But for my case I have been in a situation where I wanted some options to be disabled such that users can not select them, as they are grayed out. I am going to share my sample solution and implementation of that. I hope someone finds it useful in a scenario somewhere.

So I have a form option list with several options for booking status:
  • Submitted For Approval
  • Approved
  • Assigned
  • Started
  • Stopped
  • Ended
  • Rejected
So I want users to only be able to select Submitted For Approval, Approved And Rejected. All the other options should be disabled since they will be updated by other system processes automatically.

so in my hook files tablename-dv.js I have the following code:

Code: Select all

//disable Started;;Stopped;;Ended booking_status list options
var op = document.getElementById("booking_status").getElementsByTagName("option");
for (var i = 0; i < op.length; i++) {
  // lowercase comparison for case-insensitivity
  if (op[i].value == "Started") {
    op[i].disabled = true;
  }
  if (op[i].value == "Stopped") {
    op[i].disabled = true;
  }
    if (op[i].value == "Ended") {
    op[i].disabled = true;
  }
}
That's all, the above code will disable the Started,Ended and Stopped options as shown below:
Image

I hope this will save someone some day !! cheers

Re: How To Disable Option List Items

Posted: 2022-11-04 23:56
by angus
This is great thanks Ronald

Re: How To Disable Option List Items

Posted: 2022-11-05 23:31
by zibrahim
+ 1 from me as well. Thanks Ronald.

Re: How To Disable Option List Items

Posted: 2023-03-19 17:51
by angus
Ronald, I cant seem to get this working on 5.82 version, do you know what I need to change maybe?

Re: How To Disable Option List Items

Posted: 2023-03-20 09:58
by angus
I worked out that this works perfect for a standard drop down where we are not looking up values. where we lookup values from another table this wont work.