Append text to TextArea in the currentcursor position

Append text to TextArea in the currentcursor position


I've a question, about howto append text to the TextArea, I need to create WYSIWYG texteditor which is created with ExtJs 4. Currently what I only can useis the
TextArea.setValue("new value");
which it'll replace all the value, and what I need is that,example: I click an icon it'll write the icon after the currentcursor position.

I've already googled about this issue and also found severalsolutions which is not working:
even only to get the cursor position, in:
http://www.sencha.com/forum/showthre...l=1#post451800
or, it is also fail:
http://www.sencha.com/forum/showthre...348#post593348
and also this one:
http://hutten.org/bill/extjs/2010/11...-in-a-tex.html

it keeps saying either:
component.selection undefined
or even:
component.selection.createRange(); undefined
or
component.el.dom.createTextRange() is not afunction, (createTextRange)

I don't know why it is not working in mine, or is there a commonmistake which a person usually do?

insertAtCursor: function(v) 

{
            var document_id = this.getFocusEl().id;

 var text_field = document.getElementByIdx_x(document_id);
            

var startPos = text_field.selectionStart;
            

var endPos = text_field.selectionEnd;
            

text_field.value = text_field.value.substring(0, startPos)
            + v
            +text_field.value.substring(endPos, text_field.value.length);

            t

his.el.focus();
            

text_field.setSelectionRange(endPos+v.length,endPos+v.length);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值