<?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>Rails vs Whitewater &#187; Success</title>
	<atom:link href="http://justinspowers.com/category/success/feed/" rel="self" type="application/rss+xml" />
	<link>http://justinspowers.com</link>
	<description>Whitewater enthusiast by day, Ruby on Rails programmer by night.</description>
	<lastBuildDate>Sat, 10 Dec 2011 07:42:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Out of sight, out of mind</title>
		<link>http://justinspowers.com/2009/12/out-of-sight-out-of-mind/</link>
		<comments>http://justinspowers.com/2009/12/out-of-sight-out-of-mind/#comments</comments>
		<pubDate>Wed, 02 Dec 2009 15:19:54 +0000</pubDate>
		<dc:creator>Justin</dc:creator>
				<category><![CDATA[Photify.net]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Success]]></category>

		<guid isPermaLink="false">http://justinspowers.com/?p=55</guid>
		<description><![CDATA[So today I set up observe_form for one of my search forms. I&#8217;ve been wanting to get rid of the submit button for my form, so that when users change a search field, it would just update the search results, in real time. Think kayak.com. It took surprisingly minimal work, and the result just feels [...]]]></description>
			<content:encoded><![CDATA[<p>So today I set up observe_form for one of my search forms.  I&#8217;ve been wanting to get rid of the submit button for my form, so that when users change a search field, it would just update the search results, in real time.  Think kayak.com.  It took surprisingly minimal work, and the result just feels good.  One problem though, is that nothing happens when I change the time slider on my form.<br />
<span id="more-55"></span><br />
First things first.  There isn&#8217;t such thing as a slider on a form (at least until you get to HTML5, I believe), so I hacked a solution in.  Using a custom javascript slider, whenever the user moves the slider, a hidden_field_tag gets updated, by tying into the onSlide callback of the slider.  This hidden field is passed along with the rest of the form upon submission.  However, this hidden field isn&#8217;t being observed as part of observe_form.  I suspect it&#8217;s because javascript is doing the updating, and not the user.  Either way, I couldn&#8217;t find a rails way of fixing it.  Here&#8217;s my observe_form as it stands today:</p>
<p><code>&lt;%= observe_form  'search-form',<br />
  :before =&gt; "Element.show('spinner')",<br />
  :complete =&gt; "Element.hide('spinner')",<br />
  :url =&gt; {:action => 'search'}<br />
  %&gt;</code></p>
<p>My solution was to hook into the onChange callback of the slider itself (ignoring the hidden fields).  I used onChange instead of onSlide because I didn&#8217;t want a dozen requests going to the server per slide.  I simply added the following javascript.</p>
<p><code>Element.show('spinner');<br />
new Ajax.Request('/search',{asynchronous:true,<br />
  evalScripts:true,<br />
  onComplete:function(request){Element.hide('spinner')},<br />
  parameters:Form.serialize('search-form')});</code></p>
<p>A simple note: I suck at javascript.  Not that I&#8217;m particularly dense, I just haven&#8217;t taken the time to learn it.  I simply gleaned this little gem by using firebug to see what Rails had generated using the aforementioned observe_form, and simply modified it slightly.  Win!</p>
]]></content:encoded>
			<wfw:commentRss>http://justinspowers.com/2009/12/out-of-sight-out-of-mind/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

