<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Rails Forum - Ruby on Rails Help and Discussion Forum - Handy RJS Tips]]></title>
		<link>http://railsforum.com/viewtopic.php?id=1043</link>
		<description><![CDATA[The most recent posts in Handy RJS Tips.]]></description>
		<lastBuildDate>Thu, 10 Nov 2011 13:35:42 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Handy RJS Tips]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=146643#p146643</link>
			<description><![CDATA[<p>Thanks for the advise, it saved me loads of time and money. Highly appreciate your help))</p>]]></description>
			<author><![CDATA[dummy@example.com (zuerst)]]></author>
			<pubDate>Thu, 10 Nov 2011 13:35:42 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=146643#p146643</guid>
		</item>
		<item>
			<title><![CDATA[Re: Handy RJS Tips]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=140071#p140071</link>
			<description><![CDATA[<p>Hello HiteshGoyani,</p><p>Thanks for the code. Its really worked.</p><p><a href="http://www.chateaumontfelix.com/">chateau to rent</a> <a href="http://www.chateaumontfelix.com/bedrooms/">Loire Valley Chateau rental</a></p>]]></description>
			<author><![CDATA[dummy@example.com (jhonhud)]]></author>
			<pubDate>Tue, 03 May 2011 13:32:36 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=140071#p140071</guid>
		</item>
		<item>
			<title><![CDATA[Re: Handy RJS Tips]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=121766#p121766</link>
			<description><![CDATA[<p>&lt;% form_remote_tag :url =&gt; { :action =&gt; &#039;test&#039; }&nbsp; &nbsp;do %&gt;<br />&nbsp; Enter your name: &lt;%= text_field_tag :name %&gt;<br />&nbsp; &lt;%= submit_tag &quot;Greet Me&quot; %&gt;<br />&lt;% end %&gt;<br />&lt;h2 id=&quot;greeting&quot; style=&quot;display: none&quot;&gt;&lt;/h2&gt;<br />&nbsp; and make one rjs file and put below code<br />page[:greeting].show<br />page[:greeting].update &quot;Greetings, &quot; + params[:name]<br />page[:greeting].visual_effect :grow<br />page.select(&quot;form&quot;).first.reset</p><p>using above code you can change the greeting value</p>]]></description>
			<author><![CDATA[dummy@example.com (HiteshGoyani)]]></author>
			<pubDate>Sun, 28 Mar 2010 01:03:29 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=121766#p121766</guid>
		</item>
		<item>
			<title><![CDATA[Re: Handy RJS Tips]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=114608#p114608</link>
			<description><![CDATA[<p>I think there must be a way to get the field values from a form, I know it doesn&#039;t make sense if we limit the scope to rjs that most of the time we imply runs in the server.&nbsp; &nbsp;What if this code is part of a update_page block, that runs in the browser?&nbsp; Is there a way to extract the value from the DOM object? or is there a way to align a rjs variable with a javascript variable?</p>]]></description>
			<author><![CDATA[dummy@example.com (inguanzo)]]></author>
			<pubDate>Mon, 14 Dec 2009 05:33:29 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=114608#p114608</guid>
		</item>
		<item>
			<title><![CDATA[Re: Handy RJS Tips]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=114607#p114607</link>
			<description><![CDATA[<p>excellent tips !&nbsp; Thanks for caring!</p>]]></description>
			<author><![CDATA[dummy@example.com (inguanzo)]]></author>
			<pubDate>Mon, 14 Dec 2009 05:28:30 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=114607#p114607</guid>
		</item>
		<item>
			<title><![CDATA[Re: Handy RJS Tips]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=69404#p69404</link>
			<description><![CDATA[<p>Thanks for an immediate response <img src="http://railsforum.com/img/smilies/smile.png" width="15" height="15" alt="smile" /></p><p>1) I am a PHP developer and dont know things about RJS</p><p>2) In this scenarioo, I want&nbsp; javascript kind effect,ie a client side change. As far I know RJS is for Server side effects more like ajax, Is it true ? Please tell me little about this.</p><p>3) I want on check all checkboxes and delete all with&nbsp; destroy_all feature&nbsp; so I looped in my controller as </p><p> def manage_list_actions<br />&nbsp; &nbsp; @arrEmployees=params[:emp]<br />&nbsp; &nbsp; @arrEmployees.each{ |empl|<br />&nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp;&nbsp; &nbsp;if empl==&#039;All&#039;<br />&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;Employee.destroy_all<br />&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;redirect_to :action =&gt; :index<br />&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;params[:emp]= Array.new<br />&nbsp; &nbsp;&nbsp; &nbsp; &nbsp;else<br />&nbsp; &nbsp; &nbsp; &nbsp; @employee = Employee.find(empl)<br />&nbsp; &nbsp; &nbsp; &nbsp; @employee.destroy<br />&nbsp; &nbsp; &nbsp; &nbsp; redirect_to :action =&gt; :index<br />&nbsp; &nbsp;&nbsp; &nbsp; &nbsp;end<br />&nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; }</p><p>&nbsp; end</p><p>but this deletes all records and still loop and check for the ids (which got deleted with destroy_all) thus resulting an ERROR.</p><p>Please help.</p>]]></description>
			<author><![CDATA[dummy@example.com (yukti)]]></author>
			<pubDate>Thu, 24 Jul 2008 08:40:35 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=69404#p69404</guid>
		</item>
		<item>
			<title><![CDATA[Re: Handy RJS Tips]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=69402#p69402</link>
			<description><![CDATA[<p>you only use RJS in RJS templates, not in views (well, except using a update_page block, but that&#039;s an exception)</p><p>you already have pure javascript typed out, why do you wanna use RJS to print pure javascript into the view when you can simply print it directly`?<br /><pre name="code" class="ruby:nogutter">&lt;input type=&quot;checkbox&quot; name=&quot;emp[]&quot; value=&quot;All&quot; onClick=&quot;$(&#039;hddChkAll&#039;).value=1)&quot;&gt;</pre></p>]]></description>
			<author><![CDATA[dummy@example.com (Duplex)]]></author>
			<pubDate>Thu, 24 Jul 2008 08:31:00 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=69402#p69402</guid>
		</item>
		<item>
			<title><![CDATA[Re: Handy RJS Tips]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=69400#p69400</link>
			<description><![CDATA[<p>Hie I am trying to set a hidden field , when a person clicks on check all<br />I am unable to add the javascript (RJS) script here .</p><p> &lt;input type=&quot;checkbox&quot; name=&quot;emp[]&quot; value=&quot;All&quot; onClick=&quot;page &lt;&lt; $(&#039;hddChkAll&#039;).value=1)&quot;&gt;</p><br /><p>&lt;input name=&quot;hddChkAll&quot; id=&quot;hddChkAll&quot; value=0&gt;</p><p>This is not working <img src="http://railsforum.com/img/smilies/sad.png" width="15" height="15" alt="sad" /></p><br /><br /><p>Please help</p>]]></description>
			<author><![CDATA[dummy@example.com (yukti)]]></author>
			<pubDate>Thu, 24 Jul 2008 08:27:04 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=69400#p69400</guid>
		</item>
		<item>
			<title><![CDATA[Re: Handy RJS Tips]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=43691#p43691</link>
			<description><![CDATA[<p>Suff like that is not possible with RJS. Add some custom Javascript to the page object.<br /><pre name="code" class="ruby:nogutter">page &lt;&lt; &quot;$(&#039;people#{params[:index]}_last_name.&#039;)value = $(&#039;houshold_name&#039;).value&quot;</pre></p>]]></description>
			<author><![CDATA[dummy@example.com (Duplex)]]></author>
			<pubDate>Sun, 28 Oct 2007 22:59:54 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=43691#p43691</guid>
		</item>
		<item>
			<title><![CDATA[Re: Handy RJS Tips]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=43690#p43690</link>
			<description><![CDATA[<p>How can I grab the value of a field and set that value as the pre-populated value in a form added with rjs?</p><p>In my case</p><p><pre name="code" class="ruby:nogutter"> page[&quot;household_name&quot;]</pre><br />has the value I want to grab, and...</p><p><pre name="code" class="ruby:nogutter"> page[&quot;people[#{params[:index]}]_last_name&quot;]</pre><br />is the field I want to populate with that value.</p><p>I tried<br /><pre name="code" class="ruby:nogutter"> page[&quot;people[#{params[:index]}]_last_name&quot;].value = page[&quot;household_name&quot;]</pre><br />but that didn&#039;t work.</p><p>Thanks for your help.</p>]]></description>
			<author><![CDATA[dummy@example.com (ricsrock)]]></author>
			<pubDate>Sun, 28 Oct 2007 22:55:49 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=43690#p43690</guid>
		</item>
		<item>
			<title><![CDATA[Re: Handy RJS Tips]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=31548#p31548</link>
			<description><![CDATA[<p>And also the Prototype element API</p><p><a href="http://www.prototypejs.org/api/element">http://www.prototypejs.org/api/element</a></p>]]></description>
			<author><![CDATA[dummy@example.com (boemitsu)]]></author>
			<pubDate>Tue, 17 Jul 2007 06:48:51 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=31548#p31548</guid>
		</item>
		<item>
			<title><![CDATA[Re: Handy RJS Tips]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=31492#p31492</link>
			<description><![CDATA[<p>There&#039;s the <a href="http://api.rubyonrails.com/classes/ActionView/Helpers/PrototypeHelper/JavaScriptGenerator/GeneratorMethods.html">API</a> which is a pretty good reference.</p>]]></description>
			<author><![CDATA[dummy@example.com (ryanb)]]></author>
			<pubDate>Mon, 16 Jul 2007 20:20:56 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=31492#p31492</guid>
		</item>
		<item>
			<title><![CDATA[Re: Handy RJS Tips]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=31333#p31333</link>
			<description><![CDATA[<p>This is awesome!</p><p>Are there any resources on the web where most of the RJS functions and methods can be found? (like a reference)</p>]]></description>
			<author><![CDATA[dummy@example.com (liquid)]]></author>
			<pubDate>Sun, 15 Jul 2007 15:24:43 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=31333#p31333</guid>
		</item>
		<item>
			<title><![CDATA[Handy RJS Tips]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=5142#p5142</link>
			<description><![CDATA[<p>Here&#039;s a few RJS tips that don&#039;t seem to be documented very well. If you have a tip to share, please add it to this thread.</p><p><strong>Outputting Javascript Directly</strong></p><p>RJS is very convenient, but sometimes you want to do something which is not directly supported through RJS. You can output any kind of JavaScript you want like this:</p><p><pre name="code" class="ruby:nogutter">page &lt;&lt; &quot;document.forms[0].reset();&quot;</pre><br />This will call reset on the first form in the document, just as if you typed the javascript directly inline!</p><br /><p><strong>Selecting Multiple Tags</strong></p><p>Prototype offers the ability to select HTML elements through a powerful CSS like syntax. Ruby makes this even more powerful by allowing you to use Ruby blocks to iterate through the selected HTML elements. For example.</p><p><pre name="code" class="ruby:nogutter">page.select(&#039;form&#039;).each { |f| f.reset }</pre><br />This will reset all of the forms on the page. As mentioned the selectors are similar to CSS, so you can do this:</p><p><pre name="code" class="ruby:nogutter">page.select(&#039;.book&#039;).each { |b| b.hide }</pre><br />This will hide all of the elements with the class &#039;book&#039;. Very handy!</p><br /><p><strong>Specifying Element</strong></p><p>Most RJS helper methods take the name of the element as the first parameter. For example:</p><p><pre name="code" class="ruby:nogutter">page.replace_html :greeting, &#039;Hello World!&#039;</pre><br />This will find an HTML element with the id &#039;greeting&#039; and replace its content with &quot;Hello World!&quot;. Instead of specifying the DOM id as the first element, you can place it in square brackets like this:</p><p><pre name="code" class="ruby:nogutter">page[:greeting].replace_html &#039;Hello World!&#039;</pre><br />This feels better to me.</p><br /><p><strong>Setting Element Attributes</strong></p><p>Let&#039;s say you have a text field:</p><p><pre name="code" class="ruby:nogutter">&lt;%= text_field_tag :search %&gt;</pre><br />And you want to set the value of this text field through RJS dynamically. No problem, just grab the element as shown previously, then set the &#039;value&#039; attribute just like you would a normal Ruby object.</p><p><pre name="code" class="ruby:nogutter">page[:foo].value = &#039;Search Here!&#039;</pre><br />That is so cool!</p>]]></description>
			<author><![CDATA[dummy@example.com (ryanb)]]></author>
			<pubDate>Tue, 31 Oct 2006 04:54:36 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=5142#p5142</guid>
		</item>
	</channel>
</rss>
