How To Disable Option List Items
Posted: 2022-11-04 08:37
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:
so in my hook files tablename-dv.js I have the following code:
That's all, the above code will disable the Started,Ended and Stopped options as shown below:

I hope this will save someone some day !! cheers
So I have a form option list with several options for booking status:
- Submitted For Approval
- Approved
- Assigned
- Started
- Stopped
- Ended
- Rejected
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;
}
}

I hope this will save someone some day !! cheers