[Proto-Scripty] Re: How do you add methods to Form.Element

2009-03-07 Thread kangax

On Mar 7, 4:34 pm, Walter Lee Davis wa...@wdstudio.com wrote:
 I have this little bit of fluff:

         Element.addMethods({
                 addText: function(input, theText) {
                         if(typeof input.selectionStart != 'undefined'){
                                 var start = input.selectionStart;
                                 var end = input.selectionEnd;
                                 input.value = input.value.substr(0, start) + 
 theText +  
 input.value.substr(end);
                                 input.selectionStart = start + theText.length;
                                 input.selectionEnd = start + theText.length;
                                 input.focus();
                         }
                 }
         });

 But I want to add it only to Form.Element. I tried just tacking  
 `Form.` onto the front of this, but all I got was a syntax error.  
 Could someone clue me in how to add this method only to Form.Element?  
 (Obviously, it doesn't make much sense in a regular Element context.)

Form.Element.Methods.addText = function(){ /* ... */ };
Element.addMethods();

--
kangax
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: How do you add methods to Form.Element

2009-03-07 Thread Walter Lee Davis


On Mar 7, 2009, at 5:58 PM, kangax wrote:


 On Mar 7, 4:34 pm, Walter Lee Davis wa...@wdstudio.com wrote:
 I have this little bit of fluff:

 Element.addMethods({
 addText: function(input, theText) {
 if(typeof input.selectionStart !=  
 'undefined'){
 var start = input.selectionStart;
 var end = input.selectionEnd;
 input.value = input.value.substr(0,  
 start) + theText +
 input.value.substr(end);
 input.selectionStart = start +  
 theText.length;
 input.selectionEnd = start +  
 theText.length;
 input.focus();
 }
 }
 });

 But I want to add it only to Form.Element. I tried just tacking
 `Form.` onto the front of this, but all I got was a syntax error.
 Could someone clue me in how to add this method only to Form.Element?
 (Obviously, it doesn't make much sense in a regular Element context.)

 Form.Element.Methods.addText = function(){ /* ... */ };
 Element.addMethods();

 --
 kangax

Thanks much!

Walter


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---