Skip to content

Commit

Permalink
Autoselect on $focus
Browse files Browse the repository at this point in the history
Autoselect the value of a TextInput when the field is focused
programmatically
  • Loading branch information
Fabio Crisci committed Oct 15, 2012
1 parent d8ded56 commit b1eb132
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions src/aria/widgets/form/TextInput.js
Expand Up @@ -814,17 +814,7 @@ Aria.classDefinition({
* @protected
*/
_dom_onclick : function () {
if (this._firstFocus && this._cfg.autoselect) {
// this allow to click again and put the cursor at a given
// position
this._firstFocus = false;
var field = this.getTextInputField();
var start = 0;
var end = (field.value.length) ? field.value.length : 0;
if (end) {
this.setCaretPosition(start, end);
}
}
this._autoselect();
},

/**
Expand Down Expand Up @@ -1166,10 +1156,29 @@ Aria.classDefinition({
}
var textInputField = this.getTextInputField();
textInputField.focus();
// IE FIX: requires the value to be reset for the cursor to be
// positioned
// IE FIX: requires the value to be reset for the cursor to be positioned
// and focused at the end of the textinput.value string
textInputField.value = textInputField.value;

this._autoselect();
},

/**
* If enabled, autoselect the widget text setting the caret position to the whole input value.
* @protected
*/
_autoselect : function () {
if (this._firstFocus && this._cfg.autoselect) {
// this allow to click again and put the cursor at a given
// position
this._firstFocus = false;
var field = this.getTextInputField();
var start = 0;
var end = (field.value.length) ? field.value.length : 0;
if (end) {
this.setCaretPosition(start, end);
}
}
}

}
Expand Down

0 comments on commit b1eb132

Please sign in to comment.