search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

onShow weird behavior

Asked by Patrik
15 days ago.

I have custom implementation within our internal system

onShow: function(args) { console.log(args); top.JsEvent('onShow','"_..wcsTab_"','"_..wcsId_"', args.source.data.id);return;}

On show call basically our internal method where I do own logic to determine which button have to be disabled /enabled.

Then calling internal method which triggering JS

Method disableContextMenuItem(ID As %String, disabled As %Boolean) {

    SET dp = "T" _ ..wcsTab _ "_" _ ..wcsId

    SET js = "var index = " _ dp _ ".contextMenu.items.findIndex((el) => el.id === '" _ ID _ "');" _ 
             dp _ ".contextMenu.items[index].disabled = " _ $S(disabled:"true", 1:"false") _ ";" _ 
             "var menuItems = document.getElementsByClassName('menu_default_main')[0];" _ 
             "menuItems.children[index].children[0].className = '" _ $S(disabled:"menu_default_item_disabled", 1:"menu_default_item") _ "';"

    &js<#(js)#>

    QUIT $$$OK
}

I see correctly set enabled/disabled buttons but however, link is not working when should or working where should not. E.g where I click at the event where is 1st button enabled and then click to the 2nd event where the same button is disabled, even property is set to disabled, if you click it, function is called.

I tried to check from args.menu.items if disabled was set properly and it was. So problem must be somewhere else.

Comment posted by Patrik
15 days ago.

Forgot to mention that calling

contextMenu.update()

triggering again onShow but with error because args.source is null even contextMenu is still visible on the screen

Comment posted by Patrik
15 days ago.

Initial show of context menu

now trying to call .update, and source is gone.

Comment posted by Patrik
15 days ago.

Images which were not uploaded on post above

Answer posted by Dan Letecky [DayPilot]
14 days ago.

1. The update() method incorrectly cleared the source value, indeed. This problem should be fixed now in the latest sandbox build (2025.1.6384).

2. It’s not clear what exactly is going on in your onShow event handler. However, you can test it with the following simple example:

onShow: args => {
  args.menu.items[0].disabled = !args.menu.items[0].disabled;
  console.log("`disabled` value", args.menu.items[0].disabled);
}

This will toggle the disabled status of the first context menu item every time you open the context menu. The onShow event handler is called before the menu is rendered and the changes you make to items will be applied immediately.

You shouldn’t modify the context menu DOM directly.

New Reply
This reply is
Attachments:
or drop files here
Your name (optional):