You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by wesleywj2 <we...@yahoo.co.uk> on 2009/04/15 11:52:50 UTC

T5 How to onLoad focus() to textfield in Layout component

hi,

i'm trying to do an automatic focus on 1 of 3 textfield input upon the page
render. 

so i thought in my textfield 

<input type="text" t:type="TextField" t:value="text1"
onchange="this.form.submit()"/>

upon resubmit this page, the onLoad attribute in <body> can call the
javascript 
document.getElementById('text1').focus();

but the environment of my page is using Layout component, the textfield in
the page does not have a body and i have to include it under my layout.tml
which fails as the browser could not locate the id since its all shared by
different pages.

anyway i can set the focus upon rerender of pages under my pojo class? in
the documentation, there's no such method. any alternatives is welcome.

please advise.

thanks & regards,
wesley
-- 
View this message in context: http://www.nabble.com/T5-How-to-onLoad-focus%28%29-to-textfield-in-Layout-component-tp23055988p23055988.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5 How to onLoad focus() to textfield in Layout component

Posted by Ville Virtanen <vi...@cerion.fi>.
You can achieve this the T5 way by doing this in the page that contains the
textbox, no need to mess with layout etc. this can even be in a
component...:

  @Environmental
  private RenderSupport renderSupport;

  void setupRender()
  {
    renderSupport.addScript("document.getElementById('%s').focus();",
"text1");
  }

Of course, you can do this in afterRender also.

It is all explained in http://tapestry.apache.org/tapestry5/guide/ajax.html

Also, you can inject the textbox using @Component annotation to avoid typing
that id in plain text.

@Component
private TextField text1;
.
.
.
renderSupport.addScript("document.getElementById('%s').focus();",
text1.getClientId());

 - Ville

wesleywj2 wrote:
> 
> hi,
> 
> i'm trying to do an automatic focus on 1 of 3 textfield input upon the
> page render. 
> 
> so i thought in my textfield 
> 
> <input type="text" t:type="TextField" t:value="text1"
> onchange="this.form.submit()"/>
> 
> upon resubmit this page, the onLoad attribute in <body> can call the
> javascript 
> document.getElementById('text1').focus();
> 
> but the environment of my page is using Layout component, the textfield in
> the page does not have a body and i have to include it under my layout.tml
> which fails as the browser could not locate the id since its all shared by
> different pages.
> 
> anyway i can set the focus upon rerender of pages under my pojo class? in
> the documentation, there's no such method. any alternatives is welcome.
> 
> please advise.
> 
> thanks & regards,
> wesley
> 

-- 
View this message in context: http://www.nabble.com/T5-How-to-onLoad-focus%28%29-to-textfield-in-Layout-component-tp23055988p23057325.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5 How to onLoad focus() to textfield in Layout component

Posted by wesleywj2 <we...@yahoo.co.uk>.
thanks so much, simple and efficient. thanks much.

regards,
wesley



Thiago H. de Paula Figueiredo wrote:
> 
> Prototype comes to the rescue:
> http://www.prototypejs.org/api/event/observe.
> 
> Event.observe(window, 'load', function() {
>     $('text1').focus();
> }
> 
> -- 
> Thiago
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/T5-How-to-onLoad-focus%28%29-to-textfield-in-Layout-component-tp23055988p23059682.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5 How to onLoad focus() to textfield in Layout component

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Prototype comes to the rescue: http://www.prototypejs.org/api/event/observe.

Event.observe(window, 'load', function() {
    $('text1').focus();
}

-- 
Thiago

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org