I have a login form. I want the field to show Username and another one Password, for login.
I know how to do that with inline "onclick=''" but is there a form helper or something rails-style way to accomplish this?
I have a login form. I want the field to show Username and another one Password, for login.
I know how to do that with inline "onclick=''" but is there a form helper or something rails-style way to accomplish this?
by the way, the password field, since it's a "password" field, remember if you display something inside, a bunch of dots will be displayed instead of the word "password"
Leonel *.* wrote in post #955815:
I have a login form. I want the field to show Username and another one Password, for login.
I know how to do that with inline "onclick=''" but is there a form helper or something rails-style way to accomplish this?
Why do you need JavaScript at all for this? As you are describing it, it sounds like all you need is HTML.
Best,
Why do you need JavaScript at all for this? As you are describing it, it sounds like all you need is HTML.
Yes, sorry, my bad, you're right it's not javascript. But is there a rails-way to do it?
Leonel *.* wrote in post #955818:
Why do you need JavaScript at all for this? As you are describing it, it sounds like all you need is HTML.
Yes, sorry, my bad, you're right it's not javascript. But is there a rails-way to do it?
Yeah! Please see Action View Form Helpers — Ruby on Rails Guides regarding the Rails form helpers.
Or are you asking something else?
Best,
I know how to use the form helpers to create forms.
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.
Leonel *.* wrote in post #955832:
I know how to use the form helpers to create forms.
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.
I see that. That can be accomplished with simple JavaScript. And now I understand why you need something beyond plain HTML.
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.
Those two paragraphs are an exact repeat of an earlier post. There is no reason to do that.
You have created for yourself a technical surrogate goal (the onclick event) that may or may not be related to your real goal (have default text in your search box).
In any event, the answer is, I think, that you need to learn JavaScript to do this (do you know JavaScript yet?). Rails doesn't provide a canned helper for this AFAIK, but even if it does, you should understand what it's doing.
Are you using Prototype, jQuery, or some other JS framework on your project? A quick Google search turned up JS input-default-text (Prototype JS) download | SourceForge.net for Prototype and http://plugins.jquery.com/project/defaultInputText for jQuery.
Best,
Marnen Laibow-Koser wrote in post #955835:
Leonel *.* wrote in post #955832:
I know how to use the form helpers to create forms.
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.
I see that. That can be accomplished with simple JavaScript. And now I understand why you need something beyond plain HTML.
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.
Those two paragraphs are an exact repeat of an earlier post. There is no reason to do that.
You have created for yourself a technical surrogate goal (the onclick event) that may or may not be related to your real goal (have default text in your search box).
In any event, the answer is, I think, that you need to learn JavaScript to do this (do you know JavaScript yet?). Rails doesn't provide a canned helper for this AFAIK, but even if it does, you should understand what it's doing.
Are you using Prototype, jQuery, or some other JS framework on your project? A quick Google search turned up JS input-default-text (Prototype JS) download | SourceForge.net for Prototype and http://plugins.jquery.com/project/defaultInputText for jQuery.
Yes, I know JavaScript. I just thought there might be some magic Rails way to accomplish that task. But if there is not, its ok, I'll just try something else.
I've been using jQuery but I notice lots of Rails developers use Prototype, is there a special reason for this?
Leonel *.* wrote in post #955837: [...]
Yes, I know JavaScript.
Great.
I just thought there might be some magic Rails way to accomplish that task. But if there is not, its ok, I'll just try something else.
Well, if you just want to set the onclick event, you could use the html_options hash on the form helper, which would set the onclick attribute on the <form> tag just like any other HTML option.
I've been using jQuery but I notice lots of Rails developers use Prototype, is there a special reason for this?
Prototype was included with Rails up through version 2.3.x. jQuery hasn't been around as long.
I haven't done a heck of a lot of work with either, but it looks like Prototype may be a better designed framework in general, while jQuery has a wonderful DOM querying mechanism.
Best,
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
Robert Walker wrote in post #955914:
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.
Excellent! I think I'll start using that.
And then one doesn't need an onclick attribute: just have JS read the placeholder attribute and act accordingly to provide the functionality for browsers that don't have it.
Best,