Search code examples
comboboxmessageboxzk

Combobox gets closed on MessageBox closure ZK


I'm using ZK CE-9.0.0.

I have a combobox which I need to open programmatically, on click of OK button of the Messagebox. Hence I have implemented a Listener for the click event of the OK button. Inside the click event, I'm opening the combobox by using the following code:

EventListener<Messagebox.ClickEvent> clickListener = new EventListener<Messagebox.ClickEvent>() {
    @Override
    public void onEvent(ClickEvent event) throws Exception {
        mycombo.open();
    }
};
Messagebox.Button[] buttons = new Messagebox.Button[] {Messagebox.Button.OK};
Messagebox.show("Hi btn", buttons, clickListener);

Now the problem that I'm facing is, the combobox opens for half a second. It then immediately gets closed automatically.

As per my understanding, it's because of the Messagebox. Once the execution of the click event is completed, the Messagebox is closed & it causes the combobox also to be closed.

Please have a look at this fiddler for better understanding. Please select the ZK version to be 9.0.0 before running it.

Can anyone help me with this please?

Thanks,

RAS


Solution

  • You are correct that the main issue comes from the button retrieving focus after the animation of the combobox. The focus is given back to the button by the closed messagebox Since the combobox loose focus, the combo popup is also closed.

    A clean way to handle this would be to use an echo event to wait for the messagebox to be actually closed before sending the open action to the combobox. See this fiddle: https://zkfiddle.org/sample/1rkm5d/6-Combobox-gets-closed-on-MessageBox-close#source-2