EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: PaulMcGuinness on October 02, 2015, 05:25:58 AM



Title: How to select all text in a combobox on focus
Post by: PaulMcGuinness on October 02, 2015, 05:25:58 AM
Hi All,

This is probably really simple, but I can't seem to work it out or find it via this forum...

Essentially I just want all of the text in a ComboBox to automatically be 'selected' when it receives focus. That way the user can just start typing without having to delete the existing content first.

Cheers,

Paul


Title: Re: How to select all text in a combobox on focus
Post by: jarry on October 02, 2015, 08:33:03 AM
Please try to add a 'focus' event to the inputing box.
Code:
$.extend($.fn.combobox.defaults.inputEvents, {
focus: function(e){
var target = this;
var len = $(target).val().length;
setTimeout(function(){
if (target.setSelectionRange){
target.setSelectionRange(0, len);
} else if (target.createTextRange){
var range = target.createTextRange();
range.collapse();
range.moveEnd('character', len);
range.moveStart('character', 0);
range.select();
}
},0);
}
})


Title: Re: How to select all text in a combobox on focus
Post by: PaulMcGuinness on October 05, 2015, 05:10:44 AM
Nope, that doesn't seem to work at all. In fact if you use TAB to move between the multiple comboboxes (which *does* 'Select all'), clicking on one of them subsequently actually de-selects the text.

:(


Title: Re: How to select all text in a combobox on focus
Post by: jarry on October 05, 2015, 05:37:24 PM
Please refer to this example http://jsfiddle.net/zspwbohy/. When click the inputing box on combobox component, the text will get all selected.


Title: Re: How to select all text in a combobox on focus
Post by: PaulMcGuinness on October 06, 2015, 08:35:52 AM
Still doesn't seem to work on my system.....

Will this work on EasyUI 1.3.1 - I can't upgrade (at the moment) as there are a number of GUI issues that then appear :-/