<?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; form helper</title>
	<atom:link href="http://www.thinkbohemian.com/tag/form-helper/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>Custom jQuery UI Rails Button Form Helper</title>
		<link>http://www.thinkbohemian.com/2009/10/12/custom-jquery-ui-rails-button-form-helper/</link>
		<comments>http://www.thinkbohemian.com/2009/10/12/custom-jquery-ui-rails-button-form-helper/#comments</comments>
		<pubDate>Tue, 13 Oct 2009 02:22:14 +0000</pubDate>
		<dc:creator>Richard Schneeman</dc:creator>
				<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[button]]></category>
		<category><![CDATA[custom]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[form helper]]></category>
		<category><![CDATA[jquery ui]]></category>

		<guid isPermaLink="false">http://www.thinkbohemian.com/?p=97</guid>
		<description><![CDATA[Today I got a little bored with my standard rails buttons

Not bad&#8230;but could use a little pizazz. So I decided to take a crack at jQuery UI. A great javascript and style framework that promised to be easy to use and provides theme-able styles.
Once you&#8217;ve got jQuery UI integrated nicely into your rails project (note [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;">Today I got a little bored with my standard rails buttons</p>
<p style="text-align: center;"><img class="aligncenter" title="generate secure email button" src="../wp-content/uploads/2009/10/Screen-shot-2009-10-12-at-8.55.48-PM.png" alt="generate secure email button" width="148" height="28" /></p>
<p style="text-align: left;">Not bad&#8230;but could use a little pizazz. So I decided to take a crack at <a href="http://jqueryui.com/">jQuery UI</a>. A great javascript and style framework that promised to be easy to use and provides theme-able styles.</p>
<p style="text-align: left;">Once you&#8217;ve got jQuery UI integrated nicely into your rails project (note i had to change my url paths in the stylesheet), you can style your submit button easily by adding some classes just like this:</p>
<pre style="text-align: left;">&lt;%= f.submit "Generate Secure Email", :class =&gt; "ui-corner-all ui-state-default " %&gt;</pre>
<p style="text-align: center;"><img class="size-full wp-image-101 alignnone" title="Untitled-3" src="http://www.thinkbohemian.com/wp-content/uploads/2009/10/Untitled-3.jpg" alt="Untitled-3" width="152" height="38" /></p>
<p style="text-align: left;">Though, this isn&#8217;t 100% what I was looking for, it&#8217;s a good start. When we hover over the button, it changes color, and when we press it, our rails form submits. Though you&#8217;ll notice that the cursor doesn&#8217;t change when you hover over the button and we haven&#8217;t put an icon in it yet. To get the correct behavior i hard coded in a button:</p>
<pre style="text-align: left;">&lt;button id="user_submit" class = "ui-corner-all  ui-state-default"  type="submit" name="commit"&gt;Generate Secure Email&lt;/button&gt;</pre>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-102" title="Screen shot 2009-10-12 at 9.06.33 PM" src="http://www.thinkbohemian.com/wp-content/uploads/2009/10/Screen-shot-2009-10-12-at-9.06.33-PM.png" alt="Screen shot 2009-10-12 at 9.06.33 PM" width="169" height="36" /></p>
<p style="text-align: left;">This solved the button styling and behavior, but we still don&#8217;t have our icon. After browsing the inter webs i found a nice page of <a href="http://http://www.filamentgroup.com/examples/buttonFrameworkCSS/">jQuery-UI button demos</a> and I managed to modify my code to include a nice icon:</p>
<pre style="text-align: left;">&lt;button id="user_submit" class = "ui-corner-all fg-button ui-state-default fg-button-icon-left" type="submit" name="commit"&gt;&lt;span&gt;&lt;/span&gt;Generate Secure Email&lt;/button&gt;</pre>
<p style="text-align: center;"><img class="aligncenter" title="jQuery UI Button with rails" src="http://www.thinkbohemian.com/wp-content/uploads/2009/10/Screen-shot-2009-10-12-at-8.54.35-PM.png" alt="jQuery UI Button with rails" width="185" height="38" /></p>
<p style="text-align: left;">Perfect! It works like a dream, but it&#8217;s not very rails-esq. Lets turn this into a reusable chunk of code by making a helper method to extend form builder. In app/helpers/application_helper.rb</p>
<pre style="text-align: left;">class ActionView::Helpers::FormBuilder
    def button_with_icon(text , icon)
     object_name = self.object_name
     return "&lt;button id='#{object_name}_submit' class = 'ui-corner-all fg-button ui-state-default fg-button-icon-left' type='submit' name='commit'&gt;&lt;span class='ui-icon ui-icon-#{icon}'&gt;&lt;/span&gt;#{text}&lt;/button&gt;"
    end
end</pre>
<p style="text-align: left;">Now In my View I can put:</p>
<pre style="text-align: left;">&lt;%=  f.button_with_icon("Generate Secure Email", "mail-closed") %&gt;</pre>
<p style="text-align: left;">And I get my perfectly formatted button complete with an Icon!</p>
<p style="text-align: center;"><img class="alignnone" title="jQuery UI Button with rails" src="http://www.thinkbohemian.com/wp-content/uploads/2009/10/Screen-shot-2009-10-12-at-8.54.35-PM.png" alt="jQuery UI Button with rails" width="185" height="38" /></p>
<hr style="text-align: center;" />
<p style="text-align: left;">Note:</p>
<pre style="text-align: left;">&lt;% form_for :person, @person, :url =&gt; { :action =&gt; "create" } do |f| %&gt;
    &lt;%= f.object_name %&gt;
&lt;% end %&gt;</pre>
<p style="text-align: left;">will print out &#8220;person&#8221;, thats why in the helper we call  self.object_name on the <a href="http://caboo.se/doc/classes/ActionView/Helpers/FormBuilder.html">form_builder class.</a> Pretty cool huh?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thinkbohemian.com/2009/10/12/custom-jquery-ui-rails-button-form-helper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
