-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I'm not quite sure if this is a bug or if I'm doing something wrong (because it would be very strange, if nobody had encountered this problem earlier :) ), but I can't set the focus on a Checkbox. I tried it the following ways:
-) in Java Code
checkbox.setFocus(true);
checkbox.focus();
-) in ZUL page
<checkbox label="test" focus="true"/>
I also created a ZUL page, only with a Checkbox in it, just to be sure, that the Checkbox doesn't gain the focus and looses it again, because another component requested it, but it didn't work either.
Any hints?
Hi bpe
ZK only allow focus on below element
if (!jq.nodeName(n, 'button', 'input', 'textarea', 'a', 'select', 'iframe')) return false;
<zk xmlns:w="http://www.zkoss.org/2005/zk/client"> <checkbox label="test"> <attribute w:name="bind_"> function (dt) { this.$bind_(dt); //call the original method this.$n('real').focus(); } </attribute> </checkbox> </zk>
Hi as1225/Jimmy, thank you for your response! Unfortunately, it doesn't work. I added your piece of code to one of my checkboxes. But know I'm kinda stuck, because I don't know what to call in my Java code to get this function(dt) processed.
Maybe a further explanation, what my actual situation is: I've got an image, which is visible, and a checkbox, which is invisible. The image got an "onDoubleClick" event listener, which is going to make the image invisible and the checkbox visible and the checkbox got an "onBlur" event listener, which returns both components into the previous state. But because a "checkbox.focus();" doesn't work, I have to click the checkbox once (so it gets the focus) and not till then the "onBlur" can get active. Maybe there is another trick?
Thanks in advance!
What version of ZK are you using?
I created a sample
<zk> <zscript deferred="true"><![CDATA[ cb.setWidgetListener("onShow","this.fire('onBlur');"); ]]></zscript> <image id="img" width="100px" height="100px" src="../../../img/1.jpg" > <attribute name="onDoubleClick"><![CDATA[ img.visible = false; cb.visible = true; ]]></attribute> </image> <checkbox id="cb" visible="false"> <attribute name="onBlur"><![CDATA[ alert("onBlur"); ]]></attribute> </checkbox> </zk>
Thanks for the sample, but it seems that you misunderstood me :(
I'll try to explain it in another way: so we have an user here, who wants to change the setting of the image/checkbox pair. He double-clicks on the image, which will "transform" into the checkbox (image is now invisible, checkbox is visible). He clicks on the checkbox to change the setting. Now the checkbox got the focus. He clicks anywhere else and the onBlur event triggers, "transforming" the checkbox back into the image. Everything is working as intended!
The next day the user double-clicks the image again and the transforming happens. But now he realizes, that he doesn't want to change the setting. So he doesn't click the checkbox. But in this case, because there is no setFocus(), the checkbox doesn't get the focus on its own and therefore the onBlur event (and the transforming back) will never be triggered. Now, to trigger the onBlur, he has to click the checkbox twice, so it will get the focus, but doesn't change the setting.
It is really, really nothing more than a minor issue, but it is kinda annoying. The feature to set the focus on a checkbox would be really nice, because I don't believe there is a workaround to solve this problem.
Is it correct ?
<zk> <image id="img" src="/img/earth.png" > <attribute name="onDoubleClick"><![CDATA[ img.visible = false; cb.visible = true; ]]></attribute> </image> <checkbox id="cb" visible="false"> <attribute name="onBlur"><![CDATA[ img.visible = true; cb.visible = false; ]]></attribute> </checkbox> <zscript><![CDATA[ cb.setWidgetOverride("bind_", "function (desktop) {this.$bind_(desktop);zWatch.listen({onShow: this});}"); cb.setWidgetOverride("unbind_", "function () {zWatch.unlisten({onShow: this});this.$unbind_();}"); cb.setWidgetOverride("onShow", "function () {this.$n('real').focus();}"); ]]></zscript> </zk>
I think it is a bug
set focus shall be work
I modify my sample
<zk> <image id="img" src="/img/earth.png" > <attribute name="onDoubleClick"><![CDATA[ img.visible = false; cb.visible = true; cb.focus(); ]]></attribute> </image> <checkbox id="cb" visible="false"> <attribute name="onBlur"><![CDATA[ img.visible = true; cb.visible = false; ]]></attribute> </checkbox> <zscript><![CDATA[ cb.setWidgetOverride("focus", "function () {this.$n('real').focus();}"); ]]></zscript> </zk>
we will fix it in ZK 5.0.4
Asked: 2010-07-01 08:35:36 +0800
Seen: 2,129 times
Last updated: Aug 26 '10