[CLOSED] Field focus problem

  1. #1

    [CLOSED] Field focus problem

    I have 2 tab inside a tabpanel .I want to set focus when TAB key press on F 1 field then F 2 of TAB 2 is focused and mouse cursor pointed to F 2 .but the problem is instead of F 2 ,F 3 got focused .


    @using Ext.Net
    @using Ext.Net.MVC
    @{
        var X = Html.X();
    }
    <script>
        var SwitchTab = function (Tabpanel, Panel) {
            console.log(Tabpanel)
            console.log(Panel)
            if (Panel != 'null' && Tabpanel != 'null') {
                Tabpanel.setActiveTab(Panel);
            }
    
        }
        var SetFocus = function (Item) {
            console.log(Item);
            Item.focus();
        }
    
    </script>
    @X.ResourceManager()
    @(
    X.FormPanel()
    .Items(
     X.TabPanel().Border(false).BodyStyle("background-color: #F1F1F1;").ID("wintabpanel")
                    .Items(
    
                    // TAB
                    X.Panel().Width(480).Padding(5).Layout(LayoutType.VBox).LayoutConfig(new VBoxLayoutConfig { Align = VBoxAlign.Stretch }).AutoScroll(true)
                    .ID("t1").Title("TAB 1")
                    .Items(
      X.NumberField()
                        .ID("f1")
                        .FieldLabel("F 1")
                        .AnchorHorizontal("100%")
                        .AllowBlank(true)
                        .EmptyText("0")
                        .EmptyValue(0)
                        .LabelWidth(100)
                        .InputWidth(125)
                        .LabelAlign(LabelAlign.Left)
                         .Listeners(l => { l.SpecialKey.Handler = @"if (e.keyCode == 9) 
                                                                        {
                                                                        SwitchTab(#{wintabpanel},#{t2})
                                                                        SetFocus(#{f2});
                                                                        }"; })),
                         X.Panel().Width(480).Padding(5).Layout(LayoutType.VBox).LayoutConfig(new VBoxLayoutConfig { Align = VBoxAlign.Stretch }).AutoScroll(true)
                    .ID("t2").Title("TAB 2")
                    .Items(                                                                      
                        X.TextArea()
                        .ID("f2")
                        .FieldLabel("F 2")
                        .AnchorHorizontal("100%")
                        .AllowBlank(true)
                        .EmptyText("0")
                        .EmptyValue(0)
                        .LabelWidth(100)
                        .InputWidth(125)
                        .LabelAlign(LabelAlign.Left),
                        
                        X.TextField()
                        .ID("f3")
                        .FieldLabel("F 3")
                        .AnchorHorizontal("100%")
                        .AllowBlank(true)
                        .EmptyText("0")
                        .EmptyValue(0)
                        .LabelWidth(100)
                        .InputWidth(125)
                        .LabelAlign(LabelAlign.Left)
                        )
                        
                        )
                        ))
    please check the sample.
    Last edited by Daniil; Feb 17, 2015 at 11:45 AM. Reason: [CLOSED]
  2. #2
    Hi @matrixwebtech,

    Please add this into the SpecialKey Handler.
    e.preventDefault();
  3. #3
    Thanks for reply.problem solved.
    Why we use e.preventDefault();?
  4. #4
    It prevents the browsers default handling of the event.
    http://docs.sencha.com/extjs/4.2.1/#...preventDefault

    In your scenario, you focus a field, then the tab default behavior happens after that.
  5. #5
    Thanks daniil.this can be close.
  6. #6
    Hi,I am facing a little problem.I have three textfields tt1,tt2,tt3 and I want on tab press in tt1 set mouse focus in tt3 I use bellow code

    @(X.TextField().ID("tt1")
       .Listeners(l=>{
           l.SpecialKey.Handler = @"e.preventDefault();if (e.keyCode == 9) 
                                    {
                                        App.tt3.focus();
                                    }"; 
       })) 
    
    @(X.TextField().ID("tt2")
       .Listeners(l=>{
           l.SpecialKey.Handler = "";
       })) 
    
    @(X.TextField().ID("tt3")
       .Listeners(l=>{
           l.SpecialKey.Handler = "";
       }))
    but many keys not working in tt1 .like Delete,Back Space,Ctrl+Shift+left arrow etc... I think this is causes for
    e.preventDefault()
    ,but without that tt3 not focused after Tab press in tt1
  7. #7
    Please call e.preventDefault() only if it is needed to call. I mean that, probably, you could move it inside the if statement.

Similar Threads

  1. [CLOSED] Focus first field in RowEditor when shown.
    By pj_martins in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Nov 22, 2011, 3:50 PM
  2. Focus first field in form when TAB is pressed
    By chezinho in forum 1.x Help
    Replies: 2
    Last Post: Dec 08, 2010, 9:02 PM
  3. [CLOSED] Default field focus.
    By Jean-Pierre Poulin in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Apr 15, 2010, 11:18 AM
  4. ext:window field loosing focus
    By jmilton in forum 1.x Help
    Replies: 2
    Last Post: Aug 04, 2009, 3:06 PM
  5. Replies: 0
    Last Post: Jun 03, 2009, 3:14 PM

Posting Permissions