broberts
2008-Feb-07 21:28 UTC
Elements.addMethods()... what about specific types of INPUT elements?
What about using Elements.addMethods() to extend specific types of INPUT elements such as text, radio, checkbox, hidden, etc? Is this possible? The Prototype API documentation (http://prototypejs.org/api/element/ addMethods) does not appear to address this, but I could be overlooking it. Help! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
kangax
2008-Feb-07 22:30 UTC
Re: Elements.addMethods()... what about specific types of INPUT elements?
Just specify the tagName: Element.addMethods(''input'', { isNumeric: function(element) { return /\s*\d+\s*/.test($F(element)); } }) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
broberts
2008-Feb-07 22:40 UTC
Re: Elements.addMethods()... what about specific types of INPUT elements?
I understand that. However, what if I only want to extend a specific type of INPUT tag (e.g. RADIO, CHECKBOX or TEXT) and not every type of INPUT tag? On Feb 7, 4:30 pm, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Just specify the tagName: > > Element.addMethods(''input'', { > isNumeric: function(element) { > return /\s*\d+\s*/.test($F(element)); > } > > })--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
kangax
2008-Feb-07 22:59 UTC
Re: Elements.addMethods()... what about specific types of INPUT elements?
Nope - that is not supported. Element extension mechanism has to go through quite some pain to do what it does now. Supporting attributes would make things even more complicated. Besides, I''m not seeing practical advantage for such narrow differentiation. Best, kangax On Feb 7, 5:40 pm, broberts <brobert...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I understand that. However, what if I only want to extend a specific > type of INPUT tag (e.g. RADIO, CHECKBOX or TEXT) and not every type of > INPUT tag? > > On Feb 7, 4:30 pm, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Just specify the tagName: > > > Element.addMethods(''input'', { > > isNumeric: function(element) { > > return /\s*\d+\s*/.test($F(element)); > > } > > > })--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
broberts
2008-Feb-08 15:09 UTC
Re: Elements.addMethods()... what about specific types of INPUT elements?
kangax, Thanks for the quick reply. Attribute differentiation is obviously less crucial than the tag differentiation already supported by Element.addMethods(). I can understand the inherent complexity in the element extension mechanism, so I will gladly accept "no" as the answer to my question. However, I can see the following advantages to tag type (attribute) differentiation: 1. Better use (i.e less consumption) of memory by not extending certain types of tags with extensions that really are not meant to operate on those types of tags (e.g. TEXT versus RADIO). 2. Prevention of extensions that really are not meant to operate on those types of tags (e.g. TEXT versus RADIO) from being called and yielding unexpected results or even JavaScript errors. Of course, it could be argued that each extension should be "smart enough" to hold its own, but I think it could be argued either way. On Feb 7, 4:59 pm, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Nope - that is not supported. > Element extension mechanism has to go through quite some pain to do > what it does now. Supporting attributes would make things even more > complicated. Besides, I''m not seeing practical advantage for such > narrow differentiation. > > Best, > kangax > > On Feb 7, 5:40 pm, broberts <brobert...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I understand that. However, what if I only want to extend a specific > > type of INPUT tag (e.g. RADIO, CHECKBOX or TEXT) and not every type of > > INPUT tag? > > > On Feb 7, 4:30 pm, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Just specify the tagName: > > > > Element.addMethods(''input'', { > > > isNumeric: function(element) { > > > return /\s*\d+\s*/.test($F(element)); > > > } > > > > })--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---