PDA

View Full Version : can i have in event keydown position in textarea?



asics167
18 Dec 2013, 10:56 AM
i have textarea and want ferst 15 symbols not editable ( may be set background to red).
i think add event keydown and blocked event if position < [0,15]
but i dont know how get this position cursor in event?
e.getXY = [0,0] for all
Please help me..
Thanks

scottmartin
18 Dec 2013, 2:43 PM
If you get the cursor position, then what .. set readonly to 15 chars in the editor?

Either have a readonly field above the textarea that contains the 15 chars that has been parsed?
You can change the CSS to make the textfield look like it is part of the textarea.

remove bottom border of textfield and top border of textarea in a vbox layout.

asics167
18 Dec 2013, 10:06 PM
Okey - thanks - this very nice - spit to 2 field and erase border.. may be i do this..
but nevertheless - whether it is possible - in event keydown get number symbol in textfield( text area) ?
thanks..

PS. Yes - find this example - out it on ready.. and my keydown show current position cursor in Text fiel - text area:



Ext.override(Ext.form.field.Text, {
setCaretPosition: function (pos, dir) {
var el = this.inputEl.dom;
if (typeof (el.selectionStart) === "number") {
el.focus();

if (el.selectionStart == 0 && el.selectionEnd != el.selectionStart && el.selectionEnd == el.value.length) {
if (dir == "left") {
el.setSelectionRange(el.selectionEnd, el.selectionEnd);
}

if (dir == "right") {
el.setSelectionRange(pos, pos);
}
}
else {
el.setSelectionRange(pos, pos);
}
} else if (el.createTextRange) {
var range = el.createTextRange();
range.move("character", pos);
range.select();
} else {
throw 'setCaretPosition() not supported';
}
},

getCaretPosition: function () {
var el = this.inputEl.dom;
if (typeof (el.selectionStart) === "number") {
return el.selectionStart;
} else if (document.selection && el.createTextRange) {
var range = document.selection.createRange();
range.collapse(true);
range.moveStart("character", -el.value.length);
return range.text.length;
} else {
throw 'getCaretPosition() not supported';
}
}
});




var onkedown = function (field, e) {
console.log('KD', field.getCaretPosition() );
}


its okey for me!
many thanks all..