0

setDisabled( false ) + setFocus() does not work on previously disabled buttons

asked 2012-07-30 09:43:56 +0800

cvarona gravatar image cvarona
554 1 6

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

delete flag offensive retag edit

6 Replies

Sort by » oldest newest

answered 2012-07-30 12:07:40 +0800

TRATOR gravatar image TRATOR flag of Brazil
96 1
http://www.codelimit.com....

updated 2012-07-30 12:09:02 +0800

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>

link publish delete flag offensive edit

answered 2012-07-30 12:38:13 +0800

cvarona gravatar image cvarona
554 1 6

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

link publish delete flag offensive edit

answered 2012-08-08 05:09:24 +0800

benbai gravatar image benbai
2228 6
http://www.zkoss.org

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

link publish delete flag offensive edit

answered 2012-08-08 08:56:12 +0800

cvarona gravatar image cvarona
554 1 6

Hi Ben,

yes, the timer will do, and I'll surely end up using it. But, shouldn't it be possible to both enable a button and set the focus on it along the same event thread?

Best regards

César

link publish delete flag offensive edit

answered 2012-08-09 08:31:07 +0800

benbai gravatar image benbai
2228 6
http://www.zkoss.org

updated 2012-08-09 08:31:24 +0800

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

link publish delete flag offensive edit

answered 2012-08-10 10:53:54 +0800

cvarona gravatar image cvarona
554 1 6

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

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2012-07-30 09:43:56 +0800

Seen: 495 times

Last updated: Aug 10 '12

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More