Hi, I''m trying to sweeten up my syntax a bit. I''ve been playing around trying to work out how to do something with Selector, maybe someone can help me. I want all form elements for a form which aren''t disabled, hidden, type="button" or type="submit". basically all visible editable fields. Obviously i could just do Form.getElements( ''myForm'' ).findAll( function(e){ return !(e.disabled || [''hidden'', ''button'', ''submit''].include( e.type ) ); } ); I could make that look a little nicer by defining that predicate somewhere and just passing it in to findAll. I just thought that using a Selector might be nicer but i haven''t found an expression that works. first attempt was "select, input:not(disabled):not(type=hidden):not(type=button):not(type=submit)" including variations like @type and [] notation. Please can someone help me out. Thanks in Advance --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hey, If you look into CSS3 carefully you''ll see the selector for your needs is actually longer than your custom findAll call. It would probably go something like this (wrapped/indented for this e-mail): var fields yourForm.select(''select:not(:disabled),textarea:not(:disabled), input:not(:disabled)[type!=hidden][type!=button][type!=submit]''); Quite a mouthful. I''m not at all sure it makes for "sweeter syntax" than a custom filter: var fields = yourForm.getElements().findAll(function(e) { return !e.disabled && !''hidden button submit''.include(e.type); }); As for performance comparisons, I''m also confident the custom filter will be way faster on one-shot uses or non-XPath contexts. ''HTH -- Christophe Porteneuve aka TDD 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 -~----------~----~----~----~------~----~------~--~---
i agree, selectors really only look nicer for simple expressions. i''ve got it to myForm.getElements().findAll( activeField ) I was wondering, are there any complications with calling Element.addMethods() without arguments again? I want to add activeField to Form.Element.Methods and have that appear when i call $(). The way it works at the moment is there''s a call to Element.addMethods() at the very end of prototype.js, would it cause problems if i called it again? thanks On Feb 6, 9:13 am, Christophe Porteneuve <t...-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org> wrote:> Hey, > > If you look into CSS3 carefully you''ll see the selector for your needs > is actually longer than your custom findAll call. It would probably go > something like this (wrapped/indented for this e-mail): > > var fields > yourForm.select(''select:not(:disabled),textarea:not(:disabled), > input:not(:disabled)[type!=hidden][type!=button][type!=submit]''); > > Quite a mouthful. I''m not at all sure it makes for "sweeter syntax" > than a custom filter: > > var fields = yourForm.getElements().findAll(function(e) { > return !e.disabled && !''hidden button submit''.include(e.type); > > }); > > As for performance comparisons, I''m also confident the custom filter > will be way faster on one-shot uses or non-XPath contexts. > > ''HTH > > -- > Christophe Porteneuve aka TDD > t...-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 -~----------~----~----~----~------~----~------~--~---
It shouldn''t be a problem. Calling addMethods without arguments simply iterates over Element.Methods.* (and family) and adds them to appropriate DOM elements. c.f.: http://www.prototypejs.org/api/element/addMethods P.S. It might make sense to extend Form.Methods instead of Form.Element.Methods myForm.getElements().findAll(Form.Element.Methods.isActive) // vs myForm.getActiveFields(); On Feb 6, 1:19 pm, tgmdbm <james....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> i agree, selectors really only look nicer for simple expressions. > > i''ve got it to myForm.getElements().findAll( activeField ) > > I was wondering, are there any complications with calling > Element.addMethods() without arguments again? > > I want to add activeField to Form.Element.Methods and have that appear > when i call $(). The way it works at the moment is there''s a call to > Element.addMethods() at the very end of prototype.js, would it cause > problems if i called it again? > > thanks > > On Feb 6, 9:13 am, Christophe Porteneuve <t...-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org> wrote: > > > Hey, > > > If you look into CSS3 carefully you''ll see the selector for your needs > > is actually longer than your custom findAll call. It would probably go > > something like this (wrapped/indented for this e-mail): > > > var fields > > yourForm.select(''select:not(:disabled),textarea:not(:disabled), > > input:not(:disabled)[type!=hidden][type!=button][type!=submit]''); > > > Quite a mouthful. I''m not at all sure it makes for "sweeter syntax" > > than a custom filter: > > > var fields = yourForm.getElements().findAll(function(e) { > > return !e.disabled && !''hidden button submit''.include(e.type); > > > }); > > > As for performance comparisons, I''m also confident the custom filter > > will be way faster on one-shot uses or non-XPath contexts. > > > ''HTH > > > -- > > Christophe Porteneuve aka TDD > > t...-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 -~----------~----~----~----~------~----~------~--~---