<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>OnRails.org: remote_function :with</title>
    <link>http://onrails.org/articles/2006/05/01/remote_function-with</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Ruby On Rails and related matters.</description>
    <item>
      <title>remote_function :with</title>
      <description>&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="punct"&gt;&amp;lt;%=&lt;/span&gt;&lt;span class="string"&gt; select_tag &amp;quot;content_type&amp;quot;,  options_for_select(content_type_options),
 { :onchange &lt;/span&gt;&lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; 
    &lt;span class="ident"&gt;remote_function&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;
         &lt;span class="symbol"&gt;:url&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="punct"&gt;{&lt;/span&gt;&lt;span class="symbol"&gt;:action&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;filter_by_content&lt;/span&gt;&lt;span class="punct"&gt;'},&lt;/span&gt; 
         &lt;span class="symbol"&gt;:with&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;Form.Element.serialize(this)&lt;/span&gt;&lt;span class="punct"&gt;')&lt;/span&gt;  &lt;span class="punct"&gt;}&lt;/span&gt; &lt;span class="punct"&gt;%&amp;gt;&lt;/span&gt;&lt;span class="string"&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;The above code allows to submit via javascript the selected value of a combo box. The remote call is triggered via the &lt;em&gt;onchange&lt;/em&gt; event handler of the select tag. Notice the parameters to the remote function call &lt;strong&gt;:url&lt;/strong&gt;, as usual, but also the  &lt;strong&gt;:with&lt;/strong&gt; parameter.  The &lt;strong&gt;:with&lt;/strong&gt; option can be very useful if you need more control on what data needs to be sent to the server. In this case we use Form.Element.serialize that url encodes all the parameters found in a given div (doesn&amp;#8217;t need to be a form). In this case the &lt;em&gt;content_type=snippet&lt;/em&gt; is passed to the server.&lt;/p&gt;</description>
      <pubDate>Mon, 01 May 2006 16:08:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:b24d31e5-f99d-4495-98c0-411d1248cf92</guid>
      <author>Daniel Wanja</author>
      <link>http://onrails.org/articles/2006/05/01/remote_function-with</link>
      <category>javascript</category>
      <category>remote_function</category>
    </item>
    <item>
      <title>"remote_function :with" by Lee</title>
      <description>&lt;p&gt;Thanks for the tip, Steve.&lt;/p&gt;</description>
      <pubDate>Fri, 06 Apr 2007 23:27:09 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:0ec0ebec-61cc-4a33-addd-798b8e95f321</guid>
      <link>http://onrails.org/articles/2006/05/01/remote_function-with#comment-339</link>
    </item>
    <item>
      <title>"remote_function :with" by Steve Midgley</title>
      <description>&lt;p&gt;Hi,&lt;/p&gt;


	&lt;p&gt;If you want to send a value from an arbitrary field element (instead of &amp;#8220;this&amp;#8221;) you can use:&lt;/p&gt;


	&lt;p&gt;:with =&amp;gt; &amp;#8220;{name: Field.getValue(&amp;#8216;field_val&amp;#8217;)}&amp;#8221;&lt;/p&gt;


	&lt;p&gt;Where &amp;#8216;field_val&amp;#8217; is the value of any Field on the page. (Of course you&amp;#8217;d want to URIEncode this if field_val is user-entered text)..&lt;/p&gt;


	&lt;p&gt;Let&amp;#8217;s say the field &amp;#8220;field_val&amp;#8221; has &amp;#8220;foo&amp;#8221; in it &amp;#8211; you&amp;#8217;d end up posting this key/value pair in this example:&lt;/p&gt;


	&lt;p&gt;name=foo&lt;/p&gt;


	&lt;p&gt;Thanks for the article..&lt;/p&gt;


	&lt;p&gt;Steve&lt;/p&gt;</description>
      <pubDate>Fri, 06 Apr 2007 23:15:57 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:e28b1b32-5dd0-47dc-91d2-362a31a050e4</guid>
      <link>http://onrails.org/articles/2006/05/01/remote_function-with#comment-338</link>
    </item>
    <item>
      <title>"remote_function :with" by Carlos Forero</title>
      <description>for multiples parameters do it...

:with="Form.Element.serialize($('country_id'))+';'+Form.Element.serialize($('city_name'))"</description>
      <pubDate>Fri, 26 May 2006 20:43:09 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:7ee14d40-31ab-463b-ae0b-4bfa62750e1f</guid>
      <link>http://onrails.org/articles/2006/05/01/remote_function-with#comment-108</link>
    </item>
  </channel>
</rss>
