Hi everyone, first, i''m new to Prototype. I want to extend Prototypes Form.Element class with a few function like this: Object.extend(Form.Element,{ pointize : function(element) { if ($(element).present()) { return element.getValue().sub('','',''.''); } return element.getValue(); }, toFloat: function(element) { if ($(element).present()) { return parseFloat(element.pointize()); } return 0.0; }, toInt: function(element) { if ($(element).present()) { return parseInt(element.pointize()); } return 0; } }); But if i want to call one of these functions on an input element like $ (myInputElementId).toFloat() i always get an error that toFloat is not a function... what do i wrong? Thanx in advance! Bye Dan --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
First, you need to add to Form.Element.Methods (this will affect "input", "select" and "textarea" elements). Then, you just need to call Element.addMethods() (this will actually extend elements): Object.extend(Form.Element.Methods, { ... }); Element.addMethods(); Best, kangax Then, you just call Element.addMethods(); On Apr 9, 7:17 am, Dan <danilo.reinha...-/6JGXy0y6WPwg0mx9ZtNsQ@public.gmane.org> wrote:> Hi everyone, > > first, i''m new to Prototype. I want to extend Prototypes Form.Element > class with a few function like this: > > Object.extend(Form.Element,{ > pointize : function(element) { > if ($(element).present()) { > return element.getValue().sub('','',''.''); > } > return element.getValue(); > }, > toFloat: function(element) { > if ($(element).present()) { > return parseFloat(element.pointize()); > } > return 0.0; > }, > toInt: function(element) { > if ($(element).present()) { > return parseInt(element.pointize()); > } > return 0; > } > }); > > But if i want to call one of these functions on an input element like $ > (myInputElementId).toFloat() i always get an error that toFloat is not > a function... what do i wrong? > > Thanx in advance! > Bye Dan--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thank you! This works! On 9 Apr., 14:07, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> First, you need to add to Form.Element.Methods (this will affect > "input", "select" and "textarea" elements). Then, you just need to > call Element.addMethods() (this will actually extend elements): > > Object.extend(Form.Element.Methods, { > ...}); > > Element.addMethods(); > > Best, > kangax > > Then, you just call Element.addMethods(); > On Apr 9, 7:17 am, Dan <danilo.reinha...-/6JGXy0y6WPwg0mx9ZtNsQ@public.gmane.org> wrote: > > > Hi everyone, > > > first, i''m new to Prototype. I want to extend Prototypes Form.Element > >classwith a few function like this: > > > Object.extend(Form.Element,{ > > pointize : function(element) { > > if ($(element).present()) { > > return element.getValue().sub('','',''.''); > > } > > return element.getValue(); > > }, > > toFloat: function(element) { > > if ($(element).present()) { > > return parseFloat(element.pointize()); > > } > > return 0.0; > > }, > > toInt: function(element) { > > if ($(element).present()) { > > return parseInt(element.pointize()); > > } > > return 0; > > } > > }); > > > But if i want to call one of thesefunctionson an input element like $ > > (myInputElementId).toFloat() i always get an error that toFloat is not > > a function... what do i wrong? > > > Thanx in advance! > > Bye Dan--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---