<?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>Tatva-Artha &#187; chrome webkit rails ajax bug</title>
	<atom:link href="http://www.tatvartha.com/tag/chrome-webkit-rails-ajax-bug/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tatvartha.com</link>
	<description>meaning of &#34;it&#34;</description>
	<lastBuildDate>Sat, 22 Oct 2011 22:00:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Disabling form post in google chrome and safari</title>
		<link>http://www.tatvartha.com/2010/05/disabling-form-post-in-google-chrome-and-safari/</link>
		<comments>http://www.tatvartha.com/2010/05/disabling-form-post-in-google-chrome-and-safari/#comments</comments>
		<pubDate>Mon, 17 May 2010 22:36:07 +0000</pubDate>
		<dc:creator>Sharad</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[chrome webkit rails ajax bug]]></category>

		<guid isPermaLink="false">http://www.tatvartha.com/?p=433</guid>
		<description><![CDATA[So, I found this issue with google chrome and safari web browser and I believe this applies to any webkit based browser. When a form submit is disabled by setting the submit button to disabled=true attribute, the browser is usually expected to prevent submission when the user hits &#8220;ENTER&#8221; on any of its text fields. [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.bruceongames.com/wp-content/uploads/2009/07/Google-Chrome-Logo.jpg" style="float: right; height: 100px; width: 100px"/><br />
So, I found this issue with google chrome and safari web browser and I believe this applies to any webkit based browser. When a form submit is disabled by setting the submit button to disabled=true attribute, the browser is usually expected to prevent submission when the user hits &#8220;ENTER&#8221; on any of its text fields. This works fine in Firefor, my default browser.</p>
<p>In my rails app, I had to do this to work around this.</p>
<p>We use haml rendering engine for our project and my form looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">-</span> remote_form_for <span style="color:#0066ff; font-weight:bold;">@product_search</span>, <span style="color:#ff3333; font-weight:bold;">:url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> product_searches_path, <span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#ff3333; font-weight:bold;">:html</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>:method <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:post</span>, <span style="color:#ff3333; font-weight:bold;">:id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'product_search_form'</span><span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>form<span style="color:#006600; font-weight:bold;">|</span></pre></div></div>

<p><span id="more-433"></span><br />
This generates a form like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  <span style="color:#006600; font-weight:bold;">&lt;</span>form onsubmit=<span style="color:#996600;">&quot;jQuery.ajax({data:jQuery.param(jQuery(this).serializeArray()) + '&amp;amp;authenticity_token=' + encodeURIComponent('MlHm/z3dsdYtETKwtNnwQlojx1NIduLlWFMECbjntsM='), dataType:'script', type:'post', url:'/product_searches'}); return false;&quot;</span>
  method=<span style="color:#996600;">&quot;post&quot;</span> id=<span style="color:#996600;">&quot;product_search_form&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">class</span>=<span style="color:#996600;">&quot;product_search&quot;</span>
  action=<span style="color:#996600;">&quot;/product_searches&quot;</span><span style="color:#006600; font-weight:bold;">&gt;</span></pre></div></div>

<p>I was working with an ajax form but I believe the bug happens even with traditional form POST as reported by another user <a href="http://code.google.com/p/chromium/issues/detail?id=37402">here</a>.</p>
<p>So, I had to create an onSubmit javascript myself to fix the situation:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">-</span> semantic_form_for <span style="color:#0066ff; font-weight:bold;">@product_search</span>, <span style="color:#ff3333; font-weight:bold;">:url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> product_searches_path, <span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#ff3333; font-weight:bold;">:html</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>:method <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:post</span>, <span style="color:#ff3333; font-weight:bold;">:id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'product_search_form'</span>, <span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#ff3333; font-weight:bold;">:onsubmit</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;return jQuery.productSearchOnSubmit();&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>form<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006600; font-weight:bold;">|</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&#40;</span>function<span style="color:#006600; font-weight:bold;">&#40;</span>$<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span>
  $.<span style="color:#9900CC;">productSearchOnSubmit</span> = function<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>
    <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>$<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'#product_search_submit'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">attr</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'disabled'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>
    <span style="color:#006600; font-weight:bold;">//</span> <span style="color:#9966CC; font-weight:bold;">do</span> nothing
    <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#9966CC; font-weight:bold;">else</span> <span style="color:#006600; font-weight:bold;">&#123;</span>
      jQuery.<span style="color:#9900CC;">ajax</span><span style="color:#006600; font-weight:bold;">&#40;</span>
      <span style="color:#006600; font-weight:bold;">&#123;</span>
        data: jQuery.<span style="color:#9900CC;">param</span><span style="color:#006600; font-weight:bold;">&#40;</span>jQuery<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'#product_search_form'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">serializeArray</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">'&amp;authenticity_token='</span> <span style="color:#006600; font-weight:bold;">+</span>
        encodeURIComponent<span style="color:#006600; font-weight:bold;">&#40;</span>form_authenticity_token<span style="color:#006600; font-weight:bold;">&#41;</span>,
        dataType:<span style="color:#996600;">'script'</span>,
        type:<span style="color:#996600;">'post'</span>,
        url:<span style="color:#996600;">'/product_searches'</span>
      <span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;
    <span style="color:#006600; font-weight:bold;">&#125;</span>
    <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#0000FF; font-weight:bold;">false</span>;
  <span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#40;</span>jQuery<span style="color:#006600; font-weight:bold;">&#41;</span>;</pre></div></div>

<p>I also had to add global javascript variable for form_authenticity_token to make it available for javascript when performing submit.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">%</span>html<span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:xmlns</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;http://www.w3.org/1999/xhtml&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:lang</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;en&quot;</span>, <span style="color:#996600;">&quot;xml:lang&quot;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;en&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
  <span style="color:#006600; font-weight:bold;">%</span>head
    <span style="color:#ff3333; font-weight:bold;">:javascript</span>
      var form_authenticity_token = <span style="color:#996600;">'#{form_authenticity_token}'</span>;</pre></div></div>

<p>If you think, this is a <a href="http://code.google.com/p/chromium/issues/detail?id=37402">bug</a> too, please vote for a fix.</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.tatvartha.com/2010/05/disabling-form-post-in-google-chrome-and-safari/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

