View Full Version : InputTextMask.js

15 Jul 2014, 8:21 AM
Input Masks (Ux.InputTextMask)
Hi, I'm trying to use the UX.InputTextMask plugin form GitHub. Some updates to the DOM seem to have broken this code, specifically around the use of selections etc. I realize that GitHub is outside the scope of Sencha support, but someone may have encountered the issue and modified the plugin accordingly. The plugin can be found at ...

https://gist.github.com/loiane/909119 (https://gist.github.com/loiane/909119)

The problem code is in the methods that deal with selections (see below).
For example, the line "r = document.selection.createRange().duplicate();"
This fails as document does not have a selection object anymore. I can replace this with window.getSelction(), but createRange will fail as the object returned is a selectionRange and not a selection.

I cant figure out how to get the range object so that calls to moveEnd and moveStart succeed.

Any help appreciatd...

getCursorPosition: function() { var s, e, r;

r = document.selection.createRange().duplicate();

r.moveEnd('character', this.inputTextElement.value.length);

if(r.text === ''){

s = this.inputTextElement.value.length;

} else {

s = this.inputTextElement.value.lastIndexOf(r.text);


r = document.selection.createRange().duplicate();

r.moveStart('character', -this.inputTextElement.value.length);

e = r.text.length;

} else {

s = this.inputTextElement.selectionStart;

e = this.inputTextElement.selectionEnd;


return this.CursorPosition(s, e, r, this.inputTextElement.value);


moveCursorToPosition: function(keycode, cursorPosition) {
var p = (!keycode || (keycode && keycode.isBackspace ))? cursorPosition.start: cursorPosition.start + 1;


cursorPosition.range.move('character', p);


} else {

this.inputTextElement.selectionStart = p;

this.inputTextElement.selectionEnd = p;



29 Jul 2014, 8:49 AM
I've not worked with that user extension myself. Hopefully someone else will have had some experience working with it here on the forums. If you have contact info for the author you might reach out to him / her directly.

Good luck!