Apply same function to all dropdownlists

1 Answer 43 Views
DropDownList
Lee
Top achievements
Rank 2
Bronze
Bronze
Bronze
Lee asked on 02 Aug 2023, 07:06 PM | edited on 02 Aug 2023, 07:07 PM

I want to create a global onOpen function that will apply to all dropdownlists without the need to manually attach it to each one's open option on the site. For example, I want to hide the optionLabel if it has a class of disabled in it but I don't want to have to manually attach it to each dropdownlist created. 

                    open: function () {
                        let optionLabel = this.element.getKendoDropDownList().list.find(".k-list-optionlabel");
                        let isDisabled = $(optionLabel).find(".disabled").length > 0;
                        if (isDisabled) {
                            $(optionLabel).hide();
                        }
                    },
I know I could do something like open: onOpen, but I don't want everyone to have to remember to do that on each dropdown list. 

1 Answer, 1 is accepted

Sort by
0
Zornitsa
Telerik team
answered on 07 Aug 2023, 12:31 PM

Hello Lee,

I am afraid that there is no such default option for configuring the event handlers of all component instances globally.

A workaround for this issue could be overriding the corresponding private method for the open event of the component. Below is a link to a Knowledge Base article, which contains an example of setting a configuration globally in a DatePicker scenario:

In order to use a default event handler you could follow the approach from the article, but you will need to override the default private methods, which is not recommended. I would advise you to be careful with such implementation and keep configuring the event handlers of the components per instance.

Note, that in case you prefer to override the default behavior, you would be acting on your responsibility, so I would not recommend going for this approach.

If further questions arise, please let me know.

Regards,
Zornitsa
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Kendo family, check out our getting started resources
Tags
DropDownList
Asked by
Lee
Top achievements
Rank 2
Bronze
Bronze
Bronze
Answers by
Zornitsa
Telerik team
Share this question
or