Shadin
Shadin

Reputation: 1967

Extjs - isValid() on formPanel

Having this form panel as a login page:

Ext.create('Ext.container.Viewport', {        
 renderTo: Ext.getBody(),        
 layout:{           
 type:'fit'         
},        
 items: [           
 {         
   xtype: 'form',           
 id: 'loginForm',           
 border: false,           
 layout: {             
 type: 'vbox',              
align: 'center',              
pack: 'center'          
},       
height : Ext.getBody().getViewSize().height,       
width : Ext.getBody().getViewSize().width,      
defaultType : 'textfield',      
listeners: {               
 afterRender: function(thisForm, options){               
 this.keyNav = Ext.create('Ext.util.KeyNav', this.el, {                
enter: function(){if(loginForm.getForm().isValid())                      
 login(loginForm);              
  },                
scope: this                    
});                
}             
},...........

I'm trying to configure pressing enter for submitting, after filling the details. this line:

enter: function(){if(loginForm.getForm().isValid())

is not working properly, however, if i replace it with:

enter: function(){Ext.getCmp('firstField').getValue().length && Ext.getCmp('secondField').getValue().length

it works just fine. but i wanted to use isValid() can anyone help me please?

Upvotes: 1

Views: 2041

Answers (1)

Darin Kolev
Darin Kolev

Reputation: 3411

loginForm is not defined (at least not in the code in the question). get it by id:

 if(Ext.getCmp('loginForm').getForm().isValid()) 

Upvotes: 2

Related Questions