<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Think Bohemian &#187; rails</title>
	<atom:link href="http://www.thinkbohemian.com/tag/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.thinkbohemian.com</link>
	<description>Secede from Convention in Life and Code</description>
	<lastBuildDate>Tue, 31 Aug 2010 23:37:16 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>OnClick Rails Helper for Disqus Style Input Fields</title>
		<link>http://www.thinkbohemian.com/2009/10/11/onclick-rails-helper-for-disqus-style-input-fields/</link>
		<comments>http://www.thinkbohemian.com/2009/10/11/onclick-rails-helper-for-disqus-style-input-fields/#comments</comments>
		<pubDate>Sun, 11 Oct 2009 22:54:25 +0000</pubDate>
		<dc:creator>Richard Schneeman</dc:creator>
				<category><![CDATA[Austin]]></category>
		<category><![CDATA[Musings]]></category>
		<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[custom]]></category>
		<category><![CDATA[disqus]]></category>
		<category><![CDATA[form builder]]></category>
		<category><![CDATA[helper method]]></category>
		<category><![CDATA[input]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.thinkbohemian.com/?p=87</guid>
		<description><![CDATA[Override the default rails input field text behavior with an intuitive and easy to understand alternative using rails helper methods and simple javascript.]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;">If you haven&#8217;t seen comments by <a href="http://disqus.com/">Disqus</a>, you should probably check them out. If you don&#8217;t care about having programmatic access (as of this post) then its the simplest way of adding a comment system to your website. While their comment widget is pretty neat, i wanted to have the same effects on my input fields that they use, but with all the control and &#8220;flexibility&#8221; that rails gives me.</p>
<p style="text-align: left;">I wanted an input that had the default text grayed out, when you click on it and start typing your text becomes black, and if you delete your text and click outside of the area, the input goes back to its default value. And back to gray. To accomplish this task, i wrote my own custom helper /app/helpers/application_helper.rb:</p>
<pre style="text-align: left;">def default_text_field(name, value)

text_field(name, :value =&gt; value,  :class =&gt; "gray-input", :onfocus =&gt; "if (this.value=='#{value}') this.value = '';this.style.color = 'black';", :onblur =&gt; "if (this.value=='') {this.value = '#{value}';this.style.color = '';}" )

end</pre>
<p style="text-align: left;">So now when i use it in a view like this:</p>
<pre style="text-align: left;">&lt;%= f.default_text_field :website, "Example.com" %&gt;</pre>
<p style="text-align: left;">My view acts like this:</p>
<p style="text-align: center;"><img class="size-medium wp-image-88  alignnone" title="onClickrailsHelper" src="http://www.thinkbohemian.com/wp-content/uploads/2009/10/onClickrailsHelper-300x239.jpg" alt="onClickrailsHelper" width="300" height="239" /></p>
<p style="text-align: left;">The CSS needed for this to work properly is extremely simple:</p>
<pre style="text-align: left;">.gray-input {
color: #7a7a7a;
}</pre>
<p style="text-align: left;">Of course you can use another color if you wish. Hope you enjoyed this little tip, and I hope all your users fall all over themselves at the awesomeness of your sweet new inputs. Good luck, and happy coding.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thinkbohemian.com/2009/10/11/onclick-rails-helper-for-disqus-style-input-fields/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
