Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: Executing custom JavaScript functions in Clay dropdown component
By default, all dropdown menu items for <clay:dropdown-actions> are pointing to specific URLs.
https://dev.liferay.com/en/develop/tutorials/-/knowledge_base/7-1/clay-dropdown-menus-and-action-menus
I'd like to execute custom JavaScript methods instead.

I've done some experiments, but I am stuck now.
In my DropdownDisplayContext I've tried to specify javascript:void(0) as the href, but this value is rejected during rendering the component.
So I am using a dummy value hoping I'll be able to tweak it afterwards by JavaScript:
So tweaking clay taglib outcome afterwards sounds as a bad idea.
I'd like to avoid creating dropdown menu from scratch (expecting browser compatibility issues, responsivity challenges etc.).
https://dev.liferay.com/en/develop/tutorials/-/knowledge_base/7-1/clay-dropdown-menus-and-action-menus
I'd like to execute custom JavaScript methods instead.

I've done some experiments, but I am stuck now.
In my DropdownDisplayContext I've tried to specify javascript:void(0) as the href, but this value is rejected during rendering the component.
So I am using a dummy value hoping I'll be able to tweak it afterwards by JavaScript:
dropdownItem -> {
dropdownItem.setHref("#");
dropdownItem.setLabel("Hide Group");
});
However, by the time of executing my JavaScript any clay component markup doesn't seem to be injected into DOM yet, so I cannot neither modify href attribute or attach event listeners to the menu items.So tweaking clay taglib outcome afterwards sounds as a bad idea.
I'd like to avoid creating dropdown menu from scratch (expecting browser compatibility issues, responsivity challenges etc.).
I am able to trigger my JavaScript by replacing Clay taglib with the liferay-ui taglib. In this case I can access/alter the generated markup without problems.
https://dev.liferay.com/en/develop/tutorials/-/knowledge_base/7-1/liferay-ui-icon-menus
As the liferay-ui is AUI based, I'd still rather find more future-ready solution.
https://dev.liferay.com/en/develop/tutorials/-/knowledge_base/7-1/liferay-ui-icon-menus
As the liferay-ui is AUI based, I'd still rather find more future-ready solution.
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™