-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Just try the following in the online zk sandbox (either with ie or ff):
<window title="My First Window" border="normal" width="200px"> <button id='b1' label="b1" disabled="true" /> <button id='b2' label="b2" onClick='b1.setDisabled( false ); b1.focus();' /> </window>
Button b1 won't get focused upon pressing b2.
Any idea as to how make this work? Should I open a bug report?
With kind regards
César Varona
you can try this:
<window title="My First Window" border="normal" width="200px"> <button id='b1' label="b1" disabled="true" /> <button id='b2' label="b2" onClick='b1.setDisabled( false );' onFocus='b1.focus();' /> </window>
Hi Trator,
it works as such, but as a trick it doesn't, for in the actual scenario there is no b2 button which can be clicked and focused. Anyway I think your proposal is worthy, for it seems to prove that it works as long as enabling and focusing are carried out in different threads.
Regards,
César Varona
Hi César,
You can try it with timer
<zk> <window title="My First Window" border="normal" width="200px"> <button id='b1' label="b1" disabled="true" /> <button id='b2' label="b2" onClick='b1.setDisabled( false ); timer.start();' /> <timer id="timer" running="false" repeats="false" delay="1"> <attribute name="onTimer"> b1.focus(); System.out.println(" on timer"); </attribute> </timer> </window> </zk>
Regards,
Ben
Hi César,
It is possible if override the focus_ client side function as below:
<zk xmlns:w="client"> <window title="My First Window" border="normal" width="200px"> <button id='b1' label="b1" disabled="true"> <attribute w:name="focus_"> function (timeout) { var wgt = this, btn = this.$n('btn')||this.$n(); if (btn.disabled) setTimeout(function () { wgt.$focus_(timeout); }, 0); else this.$focus_(timeout); } </attribute> </button> <button id='b2' label="b2" onClick='b1.setDisabled( false ); b1.focus();' ></button> </window> </zk>
Regards,
Ben
Hi Ben,
I also tried to set up some timeout before attempting the focusing, like this:
<window title="My First Window" border="normal" width="200px"> <button id='b1' label="b1" disabled="true" /> <button id='b2' label="b2" onClick='b1.setDisabled( false );org.zkoss.zk.ui.util.Clients.evalJavaScript( "zk.Widget.$(\"$b1\").focus( 1000 );" );' /> </window>
and it didn't work either.
As for your last proposed solution, it looks far better than those based on timers and I think I will end up resorting to it. Anyway, and although I'm not much sure, I think this use case used to work in previous zk releases.
With kind regards
César Varona
Asked: 2012-07-30 09:43:56 +0800
Seen: 533 times
Last updated: Aug 10 '12