PDA

View Full Version : How to set the insertion point of an ExtJS text area?



SSzretter
5 Dec 2011, 7:07 AM
Is it possible / how do you set the insertion point for an Ext JS 4 TextArea?I want to insert some text (which I have working), then I want to set the insertion point at a specific length from the beginning of the field:I am getting the current contents, inserting some text in front. Now I want to move the insertion point to right after the "-":field = my ext js text area var ins = "some text I inserted - \r"; var value = ins + field.getValue();
field.setValue(value);

mitchellsimoens
5 Dec 2011, 8:15 AM
http://snipplr.com/view/5144/getset-cursor-in-html-textarea/

Pretty good write up on how to do this.

SSzretter
5 Dec 2011, 10:14 AM
That looks great, but (forgive my newb question) how do I get the 'control' reference for my Ext TextArea to pass in to the 'setCaretPosition' method?


I also found this nice sample code to extend the Ext.form.Field (see the last post):
http://www.sencha.com/forum/archive/index.php/t-95486.html


However, it's still not working so I think something is wrong with my reference (I see 'method not supported'):


me.control({
'encounteredit textareafield': {
focus:function(field,opts){
var ins = Ext.util.Format.date(new Date(),'m/d/Y h:i:s') + " - \r";
var value = ins + field.getValue();
field.setValue(value);
field.setCursorPosition(5); //uses the overide from the post referenced above
}
}
});

mitchellsimoens
5 Dec 2011, 10:33 AM
The actual <textarea> is at field.inputEl.dom