How To Disable Option List Items

Got something cool to share with AppGini users? Feel free to post it here!
Post Reply
User avatar
rngoda
Veteran Member
Posts: 124
Joined: 2020-02-05 16:00
Location: KENYA
Contact:

How To Disable Option List Items

Post by rngoda » 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:
  • 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
I'm a software engineer specializing in web database application development for complex scalable web apps.

Buy AdminLTE Plugin For Appgini: HERE
Buy Cloud Storage Plugin For Appgini HERE

Checkout AdminLTE Plugin For Appgini Tutorials On Youtube

For support Email: [email protected] Whatsappp: Me Here

angus
Veteran Member
Posts: 128
Joined: 2020-05-28 22:27

Re: How To Disable Option List Items

Post by angus » 2022-11-04 23:56

This is great thanks Ronald
AppGini 22.13

User avatar
zibrahim
Veteran Member
Posts: 137
Joined: 2020-01-28 18:30
Location: Malaysia

Re: How To Disable Option List Items

Post by zibrahim » 2022-11-05 23:31

+ 1 from me as well. Thanks Ronald.
Zala.
Appgini 24.10.1579, MacOS 14.3.1 Windows 11 on Parallels.

angus
Veteran Member
Posts: 128
Joined: 2020-05-28 22:27

Re: How To Disable Option List Items

Post by angus » 2023-03-19 17:51

Ronald, I cant seem to get this working on 5.82 version, do you know what I need to change maybe?
AppGini 22.13

angus
Veteran Member
Posts: 128
Joined: 2020-05-28 22:27

Re: How To Disable Option List Items

Post by angus » 2023-03-20 09:58

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.
AppGini 22.13

Post Reply