#1700 js: Unable to set focus

dsav Mon 14 Nov 2011

Please consider the following code:

host := Text { prefCols=40; text="localhost" }
user := Text { prefCols=40; text="guest" }
pass := Text { prefCols=40; password = true; text="" }

dlg := Dialog(window) {
  it.title = "Connect"
  it.body = GridPane
  {
    numCols = 2       
    Label { text="Host    " }, host,
    Label { text="User    " }, user,
    Label { text="Password" }, pass,
  }
  it.commands = [Dialog.ok]
}    
Desktop.callLater(1sec) |->| {
  echo("setting focus to pass field")
  pass.focus
}
dlg.open    

I intentionally called pass.focus later to be sure that all fields are initialized and shown. But it just doesn't work (at least, in JavaScript): focus is on host field, and I can do nothing about it. Is it a bug, or am I missing something?

If it's a bug, could someone please provide me a workaround, since I really need to set focus?

andy Mon 14 Nov 2011

fwt::Text probably needs to override focus handling - you can try adding (in TextPeer.js):

fan.fwt.TextPeer.prototype.focus = function(self)
{
  if (this.control != null) this.control.focus();
}

fan.fwt.TextPeer.prototype.hasFocus = function(self)
{
  return this.control != null && this.control === document.activeElement;
} 

dsav Tue 15 Nov 2011

Thanks a lot! This allows me to set focus. onFocus listeners probably should be attached to control, too. Hope, this change will be pushed soon.

andy Tue 15 Nov 2011

Great - pushed

Login or Signup to reply.