Wednesday, October 20, 2010

[Rails] Re: onclick event the rails way

Leonel *.* wrote in post #955832:
> What I want to accomplish is something similar to the LOCATION field at
> www.krop.com Do you see how it reads Live Search inside the box? As soon
> as you click on it, it disappears allowing you to enter your search
> terms.
>
> How can I accomplish the onclick="" event with a form helper in Rails or
> some other Rails way?
>
> I have a login form: Username and Password. The Username field is
> supposed to say "Username" and when you click on the field "Username"
> disappears, allowing you to enter the Username.

This is mostly for future reference, but HTML 5 offers this feature
without requiring any JavaScript at all:

<form action="/" method="get" accept-charset="utf-8">
<p><input type="search" name="search" placeholder="Search"></p>
<p><input type="text" name="username" placeholder="Your username">
</form>

Notice the placeholder attribute. This works today in Webkit based
browsers (Safari, Chrome, and even mobile Webkit browsers like one in
iOS) and maybe others.

http://diveintohtml5.org/forms.html

To get this behavior in all browser platforms then you will still have
to use JavaScript.

Rather than using the "onclick" attribute you can use Unobtrusive
JavaScript (UJS):

jQuery
---------------
$(document).ready(function() {
$('#foo').click(function() {
...
});
});

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate