Hi. I''ve got the following piece of code which is doing what it is supposed to be doing ... $(s_Form) .getElements() .without($(s_Key)) .invoke(''observe'', ''blur'', keyEdited) .invoke(''observe'', ''change'', keyEdited); I also have another bit of code which enables/disables the Reset/Submit buttons on the form ... $(s_Form) .getElementsBySelector(''input[type=reset]'', ''input[type=submit]''). invoke(b_Dirty ? ''enable'' : ''disable''); What I now want to do is amend the first bit of code to also NOT attach the events to the reset and submit buttons. I don''t know the IDs of the buttons. This code is in a library and is being added to an existing setup. I''ve had to make a small "allowance" to get the "key" element for the form. I tried ... $(s_Form) .getElements() .without ( $(s_Key), $(s_Form) .getElementsBySelector ( ''input[type=reset]'', ''input[type=submit]'' ) ) .invoke(''observe'', ''blur'', keyEdited) .invoke(''observe'', ''change'', keyEdited); But that didn''t work. I also tried ... $(s_Form) .getElements() .without ( $(s_Key), $(s_Form) .getElementsBySelector ( ''input[type=reset]'' ), $(s_Form) .getElementsBySelector ( ''input[type=submit]'' ) ) .invoke(''observe'', ''blur'', keyEdited) .invoke(''observe'', ''change'', keyEdited); But that didn''t work. I think the reason is that .getElementsBySelector returns an array and the without method wants individual elements. Any suggestions? Regards, Richard Quadling. -- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!" --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Richard Quadling
2007-Aug-14 09:55 UTC
Re: Array.without() and using an array of withouts.
On 14/08/07, Richard Quadling <rquadling-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> Hi. > > I''ve got the following piece of code which is doing what it is > supposed to be doing ... > > $(s_Form) > .getElements() > .without($(s_Key)) > .invoke(''observe'', ''blur'', keyEdited) > .invoke(''observe'', ''change'', keyEdited); > > I also have another bit of code which enables/disables the > Reset/Submit buttons on the form ... > > $(s_Form) > .getElementsBySelector(''input[type=reset]'', ''input[type=submit]''). > invoke(b_Dirty ? ''enable'' : ''disable''); > > What I now want to do is amend the first bit of code to also NOT > attach the events to the reset and submit buttons. > > I don''t know the IDs of the buttons. This code is in a library and is > being added to an existing setup. > > I''ve had to make a small "allowance" to get the "key" element for the form. > > I tried ... > > $(s_Form) > .getElements() > .without > ( > $(s_Key), > $(s_Form) > .getElementsBySelector > ( > ''input[type=reset]'', > ''input[type=submit]'' > ) > ) > .invoke(''observe'', ''blur'', keyEdited) > .invoke(''observe'', ''change'', keyEdited); > > But that didn''t work. > > I also tried ... > > > $(s_Form) > .getElements() > .without > ( > $(s_Key), > $(s_Form) > .getElementsBySelector > ( > ''input[type=reset]'' > ), > $(s_Form) > .getElementsBySelector > ( > ''input[type=submit]'' > ) > ) > .invoke(''observe'', ''blur'', keyEdited) > .invoke(''observe'', ''change'', keyEdited); > > > But that didn''t work. > > I think the reason is that .getElementsBySelector returns an array and > the without method wants individual elements. > > Any suggestions? > > Regards, > > Richard Quadling.Aha. $(s_Form) .getElements() .without ( $(s_Key), $(s_Form) .getElementsBySelector ( ''input[type=reset]'' ) .first(), $(s_Form) .getElementsBySelector ( ''input[type=submit]'' ) .first() ) .invoke(''observe'', ''blur'', keyEdited) .invoke(''observe'', ''change'', keyEdited); is working, but could it be made any neater? -- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!" --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Richard Quadling wrote:> ... > > $(s_Form) > .getElements() > .without > ( > $(s_Key), > $(s_Form) > .getElementsBySelector > ( > ''input[type=reset]'' > ) > .first(), > $(s_Form) > .getElementsBySelector > ( > ''input[type=submit]'' > ) > .first() > ) > .invoke(''observe'', ''blur'', keyEdited) > .invoke(''observe'', ''change'', keyEdited); > > is working, but could it be made any neater? > >You could do one of two things: add a "keyEdited" class to all those you want to observe, then simply call $$(''.keyEdited'').invoke(...) or you could do a more complicated CSS selector using ":not()". Maybe something like the following: $(s_Form) .getElementsBySelector(''*:not(input[type=reset]):not(input[type=submit]):not(#'' + $(s_Key).id + '')'') .invoke(...) - Ken --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Richard Quadling
2007-Aug-15 09:44 UTC
Re: Array.without() and using an array of withouts.
On 14/08/07, Ken Snyder <kendsnyder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Richard Quadling wrote: > > ... > > > > $(s_Form) > > .getElements() > > .without > > ( > > $(s_Key), > > $(s_Form) > > .getElementsBySelector > > ( > > ''input[type=reset]'' > > ) > > .first(), > > $(s_Form) > > .getElementsBySelector > > ( > > ''input[type=submit]'' > > ) > > .first() > > ) > > .invoke(''observe'', ''blur'', keyEdited) > > .invoke(''observe'', ''change'', keyEdited); > > > > is working, but could it be made any neater? > > > > > You could do one of two things: add a "keyEdited" class to all those you > want to observe, then simply call $$(''.keyEdited'').invoke(...) or you > could do a more complicated CSS selector using ":not()". Maybe > something like the following: > > $(s_Form) > .getElementsBySelector(''*:not(input[type=reset]):not(input[type=submit]):not(#'' + $(s_Key).id + '')'') > .invoke(...) > > > - KenAs a test, I used ... $(s_Form) .getElementsBySelector(''*:not(input[type=reset]):not(input[type=submit]):not(#'' + $(s_Key).id + '')'') .invoke(''observe'', ''blur'', keyEdited) .invoke(''observe'', ''change'', keyEdited) .each(function(o) { console.info(o.id); }); And my console is filled with LOADS of empty elements (those with no ids) which suggests that it is looking at everything rather than just the form elements. This is also what the dox say about getElementsBySelector(). I think I''ll create a patch for without to allow it to deal with an array of arguments as well as multiple arguments. -- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!" --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Richard Quadling
2007-Aug-15 10:06 UTC
Re: Array.without() and using an array of withouts.
On 15/08/07, Richard Quadling <rquadling-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 14/08/07, Ken Snyder <kendsnyder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Richard Quadling wrote: > > > ... > > > > > > $(s_Form) > > > .getElements() > > > .without > > > ( > > > $(s_Key), > > > $(s_Form) > > > .getElementsBySelector > > > ( > > > ''input[type=reset]'' > > > ) > > > .first(), > > > $(s_Form) > > > .getElementsBySelector > > > ( > > > ''input[type=submit]'' > > > ) > > > .first() > > > ) > > > .invoke(''observe'', ''blur'', keyEdited) > > > .invoke(''observe'', ''change'', keyEdited); > > > > > > is working, but could it be made any neater? > > > > > > > > You could do one of two things: add a "keyEdited" class to all those you > > want to observe, then simply call $$(''.keyEdited'').invoke(...) or you > > could do a more complicated CSS selector using ":not()". Maybe > > something like the following: > > > > $(s_Form) > > .getElementsBySelector(''*:not(input[type=reset]):not(input[type=submit]):not(#'' + $(s_Key).id + '')'') > > .invoke(...) > > > > > > - Ken > > As a test, I used ... > > $(s_Form) > .getElementsBySelector(''*:not(input[type=reset]):not(input[type=submit]):not(#'' > + $(s_Key).id + '')'') > .invoke(''observe'', ''blur'', keyEdited) > .invoke(''observe'', ''change'', keyEdited) > .each(function(o) { console.info(o.id); }); > > > And my console is filled with LOADS of empty elements (those with no > ids) which suggests that it is looking at everything rather than just > the form elements. This is also what the dox say about > getElementsBySelector(). > > I think I''ll create a patch for without to allow it to deal with an > array of arguments as well as multiple arguments.I''ve got the adding an ID to the Reset and Submit buttons which is in the form of s_Form + ''Reset'' and s_Form + ''Submit'', so I can use ... // Attach standard events. $(s_Key) .observe(''change'', keySelected) .observe(''keypress'', keySelected); $(s_Form) .observe(''submit'', formSubmit) .observe(''reset'', formReset) .getElements() .without ( $(s_Key), $(s_Form + ''Reset''), $(s_Form + ''Submit'') ) .invoke(''observe'', ''blur'', keyEdited) .invoke(''observe'', ''change'', keyEdited) .each ( function(o) { if (b_Debug) { console.trace(); } } ); I love the chaining I can do. -- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!" --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---