This is a migrated thread and some comments may be shown as answers.

Input keyup event operations inside dataitem.set method will lead to input loses focus

5 Answers 239 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
ye
Top achievements
Rank 1
ye asked on 17 Jun 2015, 09:41 AM

Input keyup event operations inside dataitem.set method will lead to input loses focus. 

The code is below:

 

keyupHandler: function(e){
 
    var _id = e.target.name;
    var _configItemValue = e.target.value;
    var dataItem = that.options.dataSource.get( _id );
 
     // above focus is ok
    dataItem.set( "configItemValue", _configItemValue );
 
    // input focus lost
 
    // I had hoped to focus way in this focus, but has no effect
    $(e.target).focus();
}

 

HTML Code:

<input class="k-textbox"  data-bind="events: { keyup: keyupHandler}" />

how to avoid this problem?

5 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 19 Jun 2015, 07:12 AM
Hello,

I am not sure what could cause the focus to be lost. Could you provide the full code that your using?

Regards,
Daniel
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
ye
Top achievements
Rank 1
answered on 19 Jun 2015, 07:53 AM
Attach is my full code.
0
ye
Top achievements
Rank 1
answered on 19 Jun 2015, 07:54 AM
Attach is my full code.
0
Accepted
Daniel
Telerik team
answered on 23 Jun 2015, 08:18 AM
Hello again,

The focus will be lost because the treelist will be redrawn. The set method will trigger the change event and the treelist is redrawn on change. You could restore the focus by using an approach similar to the one in the snippet below:
dataItem.set( "configItemValue", _configItemValue );
$("#treelist").find("tr[data-uid='" + dataItem.uid + "'] .searchInput").focus();
but a simpler solution would be to assign the value without the set method:
var dataItem = that.options.dataSource.get( _id );
dataItem.configItemValue = _configItemValue;
dataItem.dirty;


Regards,
Daniel
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
ye
Top achievements
Rank 1
answered on 24 Jun 2015, 02:10 AM
I tried both method, is all ok. Thanks!
Tags
General Discussions
Asked by
ye
Top achievements
Rank 1
Answers by
Daniel
Telerik team
ye
Top achievements
Rank 1
Share this question
or