(Note: This is cross-posted from the Ruby On Rails group. I thought it might be more appropriate here.) ---- As mentioned in a previous thread, I''m testing RJS templates to see if they can help me meet some requirements for a project I''m about to start. The goal is to generate forms that use AJAX to help the user understand what can be entered. In many cases, our forms have rules like "If Option A is selected then Text Field C can not be used." So I put together a small test form with two text inputs and a radio- button set: one button labeled Yes and one button labeled No. The requirements I''m trying to test are: * When Yes is clicked, hide Element 2 * When No is clicked, display Element 2 * If an element is hidden, its label is hidden * When form is first rendered for editing, Element 2 is hidden if Yes is already selected. I''ve gotten the first three down, but can''t get number four. Currently I''m using form_observer to watch for changes to my little form. And if those changes require an element to be hidden or shown, code in the RJS view file is handling that. But form_observer only fires when the form changes, not when it is first loaded. I could write code in the _form partial to hide those fields when it''s first building the form, but that''s not very DRY. I''d have the element- hiding rules in both the _form partial and the RJS template. I tried adding ":on => ''load''" to the form_observer, but that did not work. Also, creating a "periodically_call_remote" didn''t seem to do what I wanted, either. Any ideas? Thanks for pitching in with all my recent questions. Ian --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Have you tried using the Prototype 1.6.0 document.observe("dom:loaded", function() { ... }); structure? With that you can fire an even when the DOM is ready to be manipulated. Then, it shouldn''t be too hard to detect the state of the appropriate elements and hide/show the other ones. For example, I''m going to assume that yes and element2 are actual IDs of elements in your page, you could do this: document.observe("dom:loaded", function() { if($("yes").checked) $("element2").hide(); }); That should hide element2 when the DOM is loaded by default. - Dash --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
That''s pretty much exactly what I ended up doing, yes. I forgot to post here that I''d solved the problem. Thanks for your help! On Dec 14, 2:39 pm, dashifen <dashi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Have you tried using the Prototype 1.6.0 > document.observe("dom:loaded", function() { ... }); structure? With > that you can fire an even when the DOM is ready to be manipulated. > Then, it shouldn''t be too hard to detect the state of the appropriate > elements and hide/show the other ones. > > For example, I''m going to assume that yes and element2 are actual IDs > of elements in your page, you could do this: > > document.observe("dom:loaded", function() { > if($("yes").checked) $("element2").hide(); > > }); > > That should hide element2 when the DOM is loaded by default. > > - Dash--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---