Clicking on Menu Tree item runs a script

I want when I click on menu tree item instead of opening a page it run python script.
How should I do that?

Hi @nader.chinichian, there is a component event called onItemClicked where you can run a script based on what was clicked. You’ll just need to filter the the items by label or something similar:

1 Like

Thansks Joshua,
By the way so if I want to open my main view I have to use script or is there another way to do that? I mean I cant find any property for opening view on Menu Tree. There is only property for opening page.

No prob! If your main view is setup via a Page Configuration path (shown below), you can assign that path to the target property of a menu item and that view will be shown. If you’re looking to do something semi custom like a popup or displaying a view that isn’t bound to a path, you’ll need to do that via script. In that case, just leave the target property blank for the menu item that you want to trigger this behavior, and use the script.

Perspectives Page Configuration

1 Like

If I have some sub item menu and need to password protect them in the parent Item, How can I do this?
I can setup check password on Parent Item onItemClicked like you said and open page manually but how can I force it to go to sub menu?

I think you might be better off using a script that would conditionally create the child items based on the password check. That way they just don’t exist until that check has been met. Alternatively, you could enable/disable menu items based on the password check, if that would work for your use case.

Thanks. good idea.
for your second one, where the props for enable disable menu item?

Each menu item has an enabled property that allows it to be actionable. If set to false, the menu item won’t open child items or navigate to a destination.