Project

General

Profile

PopupMenuItem works, then doesn't

Added by Christian Meyer 7 days ago

Hi all,

I am about to get mad ...

I reboot my Computer, start the Server and selecting the Items in the PopupMenu works. The Dialogs are Created, the Terminal shows the request, also logs whats given in the handler.

Then I change a line within the handler, try again and now the selection of an Item does not trigger the handler.
Terminal shows the request, but no dialog is shown and also no logs from inside the handler.

Then on reboot it works again until I change something completely unrelated...

I don't even know where to start looking.

Sometimes the handler works after trying multiple times...
then it doen't again.

This is the Item create Code

Just tested with Chrome and Firefox.

This worked fine for a while!
Every click triggered the desired action.
Then it started not wanting to trigger twice.
Now it dosn't trigger at all.

Showing the popupMenu on button click works always.
Although I had a problem with the default button->setMenu() and used my own implementation.
(The popupMenu wouldn't close on blurred by default, unlike in the widget gallery)

Any help and tips where to look are highly anticipated.

I am almost done with this and ready to publish, but this is hopefully understandable a NoGo.


Replies (8)

RE: PopupMenuItem works, then doesn't - Added by Christian Meyer 6 days ago

this is coming through the request:

Dev-Tools Request after clicking Item when nothing happens

Dev-Tool Request when Dialog Shows as Expected

I shortened the HTML Output for the internal Dialog, but kept the js intact.

There is a clear difference

And Trying to open the Dialog in the first Place here is the log on the Server
Server Log

Closing the Dialog returns this Code:

Wt._p_.response(3115086265);Wt4_11_4.remove('o1kbq4ls');Wt4_11_4.remove('o1kbq4ji');setTimeout(function() {Wt._p_.updateGlobal(null) });
Wt._p_.setFormObjects(['o1kbq4gd','o1kbq4h9','o1kbq4hc']);

Is there anything that comes to mind why this would make sense?

[SOLVED]: PopupMenuItem works, then doesn't - Added by Christian Meyer 6 days ago

It got weirder

But then After Consulting with AI a possible problem could be a timing missmatch.

Apparently my Implementation of the triggering PopupMenu button used the blurred() Signal to close the popupmenu and update the button style.

This aparently closed the Menu to fast for the click to reach the menuitem.

The Solution was to add a singleshot Timer of 1ms to the blurred event that then updated the button and closed the menu.

Now it works as expected

I just need to revisit the button with the popupmenu.
the current implementation has its drawbacks as well ... in some edgecases I was made aware of with the workaround.

I will check the default implementation again, maybe it just works now ...

Thank you for reading, hopefully this helps someone someday

Cheers
Christian

RE: PopupMenuItem works, then doesn't - Added by Matthias Van Ceulebroeck 6 days ago

Hey Christian,

that sounds like a very annoying issue, especially since it's not reliably reproducible (but seemingly random).
I don't have a intimate knowledge of the blur event, but I suspect you encountered a case where an event did not bubble.

I can see that for a WSuggestionPopup, we use the blur event, to hide the dropdown (popup), with a delay in JS (using setTimeout()). That makes me suspect there can be timing related issues with blur itself.

Is there a specific reason you are using blur over WPopupMenu::aboutToHide() or WPopupMenu::triggered()?

Best,
Matthias

RE: PopupMenuItem works, then doesn't - Added by Christian Meyer 6 days ago

Hi Matthias,

aboutToHide() works as well, even better it does not have the edge case that I introduced.

One reason not to use (allthough I did not explicitly test it) was the language in the description of the function.

"Signal emitted when the popup is hidden."
But it does not say how that comes to be.
(After Seletion, after clicking out, navigating awai ...)

I had trouble earlier that the implementation with button->setMenu() did not hide the popup when opening a new tab in a tabbed widget. The popup would still float about and wouldn't close.

That is one of the reasons.

triggered() I did not use because it seems that would never trigger if nothing would be selected.
And I want the menu to close when its opened, but nothing selected, and navigated away from the view.

blur() worked as expected for a long time before it started to show these symptoms and randomness.

RE: PopupMenuItem works, then doesn't - Added by Matthias Van Ceulebroeck 6 days ago

Hey Christian,

did the issue with the popup not closing arise when the button on which the popup appeared was inside the tab widget, or outside?
In both cases is should hide of course, first by dom tree visibility (although we handle popups a little different, but it ought to be consistent), or second by losing focus.

RE: PopupMenuItem works, then doesn't - Added by Christian Meyer 5 days ago

I just tested it with setMenu()

The Button is bound to a template. This Template is repeated on the first Page of a WStackedWidget. The whole templated Widget reacts to a clicked()-Event.
The Template

The click() triggers the creation of a new closable Item in a WMenu that is connected to the WStackedWidget and changes to it.

I now bound the PopupMenu to the button with setMenu() and the only interaction I can do with the Button, is open the PopupMenu.
Clicking away, without selecting an Item does not hide the PopupMenu.

But I also would like to be able to close the popup with a click on the button, or when i do not select an item and click somewhere else.

As the button is nested in a Widget that reacts to clicked() I had to set btn_Menu->clicked().preventPropagation();.

Because of that I think I build the other Implementation:

Button Checked variant

With this I can Open and Close the Popup on the button click.
Closing it with blurred() worked a while as laid out before ...

Maybe it's because of the event propagation prevention that the default functionality does not work.

I am somehow surprised that the aboutToHide Signal works when the button or the Popup loses Focus.
And it doesn't with the default way of setMenu.

Hope this helps to track it down ...

RE: PopupMenuItem works, then doesn't - Added by Christian Meyer 5 days ago

Returning Everything, and me saying I am surprised -> had it coming

popup does not hide on lost focus anymore!

Now this error showed up in the commandline
Uncaught TypeError: e.originalEvent is undefined

This error is triggered when I close the popup, or when I click somewhere when its open and is fired as long as the popup is open.

propably the other reason to use the blurred signal ;)

RE: PopupMenuItem works, then doesn't - Added by Matthias Van Ceulebroeck about 16 hours ago

I'll ping this to remind myself to take a look at this later.

I'm not all too sure how much we can do about the propagation itself. But the TypeError definitely should NOT occur.

    (1-8/8)