On 7/31/06, Mohit Sindhwani <mo_mail@onghu.com>
wrote:>
> Vince W. wrote:
> > I have a text field that I use for logging in users. Due to the
design
> > of my site, I don''t have room to put the word
"username" in front of the
> > text field so I''d like to actually display it inside the
field and then
> > have the word clear when the user clicks on it.
> >
> > How could I modify something like this
> >
> > <%= text_field "user", "login", :size => 15
%>
> >
> > to do that?
> >
> > Thanks..
> >
> >
> Hi Vince,
>
> I think you need to use '':value=>...'' for this:
> <%= text_field "user", "login", :value =>
''username'', :size => 15 %>
>
> Hope this helps.
> Cheers
> mohit.
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
The value option is definitely required. Also if you want it to go blank
when the user clicks in it then you will need some JS. You will need to
give your username text_field an HTML id parameter so you can reference it
in the JS. Somthing like
function clear_usernamed( dom_id ) {
if $( dom_id ).value == "username" {
$( dom_id ).value = "";
}
}
and your field
<%= text_field "user", "login", :value =>
''username'', :size => 15, :onFocus
=> "clear_username( ''user_login'');'' %>
Then call this on the onFocus action for your username field. I''m not
exactly sure of the format for onFocus. :on_focus, :onFocus,
''onFocus''
Unless someone else can help you''ll need to experiment.
If you really want to make it really nice you could include this in a
behaviour, but the basic case above should work.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060731/a1cdbcae/attachment.html