balanv
balanv

Reputation: 10898

Calling JS within a simple form input (Rails)

I am using simple form in my application, i have an inline js to set field name and unset when user clicks on the field and modify it as shown below

input type="text" class="ftext" value="First Name" onclick="if(this.value=='First Name') this.value='';" onblur="if(this.value=='') this.value='First Name'"

I am trying to do this with simple form inpt <%= f.input :password, :required => true, :class => "ftext" %>, but cannot able to find any solution in web.

Please suggest me on this.

thanks, Balan

Upvotes: 2

Views: 7492

Answers (2)

Sushant
Sushant

Reputation: 427

Anything like this works for rails 5

<%= f.input :email, :required => true, :autofocus => true, onclick: "yourFunction()" %>

Upvotes: 1

balanv
balanv

Reputation: 10898

We can do this by using "input_html" option as shown below :

<%= f.input :email, :required => true, :autofocus => true, :input_html => { :onclick => "customFunction()", :class => "stext", :style => "padding-left:93px;width:170px;" } %>

Upvotes: 2

Related Questions