• If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Announcement

Collapse
No announcement yet.

Form field focus when not defaultFocus field

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Form field focus when not defaultFocus field

    Hi Guys,

    I'm thinking what I want to do doesn't exist. The defaultFocus config for Window has a Getter but no Setter method. Is there anyway to alter what field will get focus dynamically, as I'm sending Window/form to show?

    I've got code hiding the field in defaultFocus config under certain data condition, I then want to set focus on a field in a conditional fieldset. I'm using focus() on the field I want but Extjs just sets focus on the field proceeding the one I'm hiding. Disable() and hide() behave same way, just sets focus on field before it. And strangely, it's not even the first input field on form.

    I have code from examples in past where, after server post returns field in error and the error msg, the code retrieves Field object in variable and runs markInvalid function to set the red outline. It then calls the focus() method on that field but I've never seen it work. I'm guessing at prior version of Extjs (2 or 3) this may of worked. So thinking it is same problem I'm asking about above.

  • #2
    Hi Terry,

    You could do away with the defaultFocus and just listen for the afterrender event on the two fields in question and programmatically focus one of them

    Code:
        xtype: 'formpanel',
        items: [{
            xtype: 'textfield',
            name: 'name',
            itemId: 'nameField',
            label: 'Name',
            listeners: {
                afterrender: function (cmp) {
                    // if not hidden auto focus
                    //
                    if (!cmp.isHidden()) {
                        cmp.focus(true, 120);
                    }
                }
            }
        }, {
            xtype: 'emailfield',
            name: 'email',
            label: 'Email',
            listeners: {
                afterrender: function (cmp) {
                    var nameField = cmp.up('form').down('#nameField');
    
                    // if the name field is hidden this auto focus this field
                    //
                    if (nameField.isHidden()) {
                        cmp.focus(true, 120);
                    }
                }
            }
        }]

    Comment


    • #3
      Hi Johnny, Unfortunately that technique won't work unless I move away from Show/Hide to creating and destroying object after every use. This is heavily reused Win/Form, not the best option for that technique.

      But your answer has confirmed what I was looking for, I haven't missed something in the documentation. I wanted to ask because many times before I thought it was dead end and you or Sean showed me it was not. :-) I can live with this one, they have several UI events to execute in no particular order anyway when that Window used. Thanks for quick reply and take care!

      Comment


      • #4
        Or is show() something that triggers a afterrender event? I'm thinking not.....?

        Comment


        • #5
          Terry,

          The afterrender event is fired when a component is created

          Comment

          Working...
          X