EasyUI Forum
May 15, 2024, 04:40:13 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: How to select all text in a combobox on focus  (Read 9077 times)
PaulMcGuinness
Newbie
*
Posts: 15


View Profile Email
« 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
Logged
jarry
Administrator
Hero Member
*****
Posts: 2264


View Profile Email
« Reply #1 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);
}
})
Logged
PaulMcGuinness
Newbie
*
Posts: 15


View Profile Email
« Reply #2 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.

Sad
Logged
jarry
Administrator
Hero Member
*****
Posts: 2264


View Profile Email
« Reply #3 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.
Logged
PaulMcGuinness
Newbie
*
Posts: 15


View Profile Email
« Reply #4 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 :-/
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!