Reputation: 2760
Given the following:
$("#dataField").focus().autocomplete({
minLength:5,
cache:false,
source:"${request.contextPath}/ajaxActions/getdata",
select:function (event, ui) {
populateForm(ui);
}
});
How could I change the focus function such that it would place the cursor at the end of the input's current value?
Upvotes: 1
Views: 888
Reputation: 3989
I haven't actually tested this, but it should more or less do what you need.
(function( )
{
var oldFocus = $.fn.focus;
$.fn.focus = function( arg1, arg2 )
{
// ======== Call Old Function
var result = oldFocus.apply( this, arguments );
// ======== Additional Functionality
// Logic here to move your cursor
return result; // -- this preserves ability to chain
}
})( );
For actually moving the cursor, see this SO question: move cursor to the beginning of the input field?
Upvotes: 1
Reputation: 5115
$("#dataField").focus(function() {
$(this).val($(this.val());
}).focus();
This approach is the jQuery way of doing the stuff in this link and thus should do what you require.
Upvotes: 1