-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hello,
I need an event that runs before the onCheck on radiogroup because when the users changes his already made selection I want to warn him that this change will affect his work somehow and I'll show a messagebox asking him if he is sure of what his is doing.
Is there an event to do this?
Regards
Hi Mansari,
You can register client side event listener on a "onClick" or "onMouseDown" event and event.stop will stop the event.
You can implement some javascript logic, either directly or in a function. for a simple example:
<zk>
<radiogroup xmlns:w="client">
<radio label="test1"/>
<radio w:onClick="if(!window.confirm('Are you sure?')){event.stop();}" label="test2"/>
</radiogroup>
</zk>
This will happen on Client side directly.
Regards
Update: You can also register these widget listeners from a composer or a renderer if you are creating components from java, and not a zul file.
The current data flow and implementation is
1. browser change radio status and visual presentation.
2. ZK client engine was called that the status of the radio changed, and send the onCheck command back to server as an Ajax Request.
3. server receive the command and change the server side radio component status and post onCheck event to the radiogroup component.
4. applciation event listener do its job.
So it shall be the way you have done.
Hmmmm, i think in this case i would do it like you.
An additionally event like you shows ( onChecking() event ) needs the logic for cancelChecking()
who will stop the chain to go further to the the onCheck() event. From the lines of code it's nearly the same.
Or the component must be extended: event.getTarget().cancelChecking();
Interessting to know what the zkTeam think about that.
best
Stephan
For now the radiogroup only have 2 radios and I manage to solve the issue with onCheck, see:
public void onCheck_radio(CheckEvent event) { if (pedidoVendaFacade.current.itens) { def opcao = Messagebox.show("are you sure? it will remove data", "", Messagebox.YES | Messagebox.NO, Messagebox.QUESTION); if (opcao == Messagebox.YES) { pedidoVendaFacade.current.removeAllItens() reloadItens() } else { radio.selectedIndex = radio.selectedIndex == 0 ? 1 : 0; } } }
I don't think this is a good solution, we should have an event that allow us to make pre-process and to cancel if needed, for example:
public onChecking_radio(Event event) { // ask the user if his is sure if (notSure) { cancelChecking(); } }
Asked: 2009-11-12 07:04:44 +0800
Seen: 476 times
Last updated: May 13 '16