Does anyone knows how to do an observe field using Prototype in Rails 3. An example would be useful as I am very weak programming in Ajax. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Don Mapp wrote in post #956253:> Does anyone knows how to do an observe field using Prototype in Rails > 3. An example would be useful as I am very weak programming in Ajax.Prototype ------------------- document.observe("dom:loaded", function() { $(''foo'').observe(''click'', function(event) { this.setStyle({backgroundColor: ''blue''}); }); }); jQuery ------------------- $(document).ready(function() { $(''#foo'').click(function() { $(this).css("backgroundColor", "blue"); }); }); Notice that this begins observing the "click" event on the element with id="foo" attribute. Also, notice that it waits for the DOM to fully load before attaching the event listener. If you want to observe something other than "click" the just replace that with the event you want to observe (e.g. "change"). -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> jQuery > ------------------- > $(document).ready(function() { > $(''#foo'').click(function() { > $(this).css("backgroundColor", "blue"); > }); > }); >Sorry but this is not equivalent to observe this is $(document).ready(function() { $(''#foo'').live("click",function() { $(this).css("backgroundColor", "blue"); }); }); and it can be shorter $($(''#foo'').live("click",function() { $(this).css("backgroundColor", "blue"); })); -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
to explain my previous comment, if you do $(document).ready(function() {> $(''#foo'').click(function() { > $(this).css("backgroundColor", "blue"); > }); > }); >and you change the node holding the "foo" element, since you attached the click event on document ready, the event will not work again after the change, so with the live event you make the browser keep looking for "foo" element like the observe event from prototype, so if you update somehow the "foo" element the click event will be reattached -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks GUys I will try that and get back to you sometime. On Oct 22, 3:41 pm, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> to explain my previous comment, if you do > > $(document).ready(function() { > > > $(''#foo'').click(function() { > > $(this).css("backgroundColor", "blue"); > > }); > > }); > > and you change the node holding the "foo" element, since you attached the > click event on document ready, the event will not work again after the > change, so with the live event you make the browser keep looking for "foo" > element like the observe event from prototype, so if you update somehow the > "foo" element the click event will be reattached-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.