1

Is it possible / how do you set the insertion point for an ExtJS 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 ExtJS text area
var ins = "some text I inserted - \r";
var value =  ins + field.getValue();                            
field.setValue(value);
JamesHalsall
  • 13,224
  • 4
  • 41
  • 66
Scott Szretter
  • 3,938
  • 11
  • 57
  • 76

2 Answers2

0

qaScriptForm is a normal form

Script is a normal TextArea

var insertIndex = qaScriptForm.Script.selectionStart;
var value = qaScriptForm.Script.value;
value=value.substr(0,insertIndex)+ " DATEADD(DAY,-7,GETDATE()) "+value.substr(insertIndex);
qaScriptForm.Script.value=value;
Michaël
  • 3,679
  • 7
  • 39
  • 64
0

There's no out-of-the-box method that allows this.

Javascript security doesn't allow you to fire a keypress event, so you can't focus the textarea and then fire the "CTRL+END" key combo, or even the "END" key, for example.

I played around with the focus() and select() methods on the <textarea> element, with no success being able to get the cursor to appear at the end.

So my answer is that you shouldn't attempt this until it's officially supported, because even if you get a hack to work, it might only function properly in some browsers.

JD Smith
  • 1,764
  • 15
  • 17