Defautl Form Text_field
Join the DZone community and get the full member experience.
Join For FreeSimple default text in text field until you click it
<%
def text_field_fade(default, field, form, options = {})
if form.object[field].blank?
options[:class] = "#{options[:class]} fade" unless options[:class].blank?
options[:class] ||= "fade"
options[:value] = default if options[:value].blank?
%(
#{form.text_field field, options }
)
else
%(
#{form.text_field field, options }
)
end
end
%>
<% form_for User.new(:first_name => "asdf") do |f| %>
<%= text_field_fade("FIRST NAME", :first_name, f)%>
<%= text_field_fade("LAST NAME", :last_name, f)%>
<%= text_field_fade("LOGIN", :login, f)%>
<% end %>
Form (document)
Opinions expressed by DZone contributors are their own.
Comments