Hi, I''m implementing a generic form validation script for a site that I''m working on. When validation fails for an input of a given id, it uses the $$ function to select all elements with a class of "validationFail_{input ID here}" and shows them. The goal is to have elements on the page that can be displayed when validation fails and hidden when it succeeds or the other way around. The $$ has never really been a performance problem for me in the past, however I suspect that the quantity of "classic" HTML development done way before I was working on this site is making the function iterate over a great amount of elements. So, my question is: Is there a way to make the $$("selector") function take a root node to search? Ex: $$("selector", $(formID)) would only iterate over elements in the form. The only other route that I have come across is optimizing the function with Sylvain Zimmer''s method, available here: http://www.sylvainzimmer.com/index.php/archives/2006/06/25/speeding-up-prototypes-selector/ Thanks in advance for any help you can offer. Mike Kelp --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Mike Kelp wrote:> Hi, I''m implementing a generic form validation script for a site that > I''m working on. > > When validation fails for an input of a given id, it uses the $$ > function to select all elements with a class of "validationFail_{input > ID here}" and shows them. The goal is to have elements on the page that > can be displayed when validation fails and hidden when it succeeds or > the other way around.Why not use CSS and just modify the style rule? You could also use getElementById (or $(id) if you insist) and change the style or CSS of the appropriate elements. -- Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks for the response Fred. I''d still like to know if there is a way to do what I was asking before, but I am interested in modify style rules directly. Could you provide a cross-browser (scriptaculous quality) example of modify a css rule effectively? For the most part, I should just need to modify the display property of the ".validationFail_fieldID" classes (or create the rule if it doesn''t exist). Thanks again, Mike. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Mike Kelp wrote:> So, my question is: > Is there a way to make the $$("selector") function take a root node to > search? > Ex: $$("selector", $(formID)) would only iterate over elements in theSure, it is just a CSS selector. So: $$(''#formID selector'') This will find the element with id "formID" first using document.getElementById (fast). Then search on the child nodes of that element for the right elements that match "selector". Eric --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Well, ironically enough...I thought I had tried this, but I may have messed up becaused after attempting adding the #id selector again, the speed is much better. Maybe I got tricked by the browser cache. I apologize for wasting anyone''s time. Thanks, Mike. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Eric Anderson a écrit :> $$(''#formID selector'')FYI, this sure works, but $(''formID'').getElementsByClassName(''selector'') is reputed to be faster (as it removes lexical analysis, relies on XPath when it''s there, and otherwise relies on partial DOM traversal with Element.hasClassName). -- Christophe Porteneuve a.k.a. TDD "[They] did not know it was impossible, so they did it." --Mark Twain Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Mike Kelp wrote:> Thanks for the response Fred. > > I''d still like to know if there is a way to do what I was asking > before, but I am interested in modify style rules directly. Could you > provide a cross-browser (scriptaculous quality) example of modify a css > rule effectively?Unfortunately, no. The vaguaries of browser implementations make a general solution impossible, though if you want only IE and Firefox, and maybe Opera 8+, it is possible to make a reasonably comprehensive solution for an intranet (e.g. Opera <8 didn''t have a styleSheets collection).> For the most part, I should just need to modify the > display property of the ".validationFail_fieldID" classes (or create > the rule if it doesn''t exist).If that is your scheme, why not assign validationFail_fieldID as the ID of your error element rather than the class and set the property directly? That''s what I do now. getElementByClassName is very much a kludge and should only be used as a last resort (that is not an anti-prototype.js rant, just an opinion in general, however it is implemented). -- Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---