//Specify the provider for remote calling. Note that it cannot be specified in initComponent, because the config attribute is set before initComponent, and an api not found error will be reported
Ext.direct.Manager.addProvider(Ext. app.REMOTING_API);
//loginForm class, inherits Ext.form.FormPanel, uses alias to register to ComponentMgr, and the upper object is dynamically instantiated using xtype:LoginFormPanel.
//The submit() method of form uses Direct submission. When the upper object instantiates this class, use the api attribute in config to specify the server-side method.
//It is very strange that the api attribute cannot be specified in Ext.define or Ext.apply. If it is specified, it will be lost after instantiation, and then an error that there is no url parameter will be reported. You can only instantiate this class in the upper object. When using the api attribute in config to specify the api
//If you use the original new method to specify the api here, it is also OK. Is it a problem in ext4? If anyone knows, send me an email. Thank you very much~~
//Use Ext.define to define this class, and use initComponent in the definition to specify the operations that need to be performed before instantiation.
//According to the idea of object-oriented programming, this class does not call any upper-level objects, and no scope is specified in the method: this
Ext.define('Ext.app.LoginFormPanel',{
extend:'Ext. form.FormPanel',
initComponent: function(){
//The functions that need to be completed in the initialization part
//alert("Ext.form.FormPanel starts loading...");
// It seems that the attributes obtained by Ext.apply are no different from those defined in Ext.define. Why should I use this?
Ext.apply(this, {
//labelAlign: 'left '
});
this.callParent();
},
alias:'widget.LoginFormPanel',
labelAlign: 'left',
buttonAlign: 'center',
bodyStyle: 'padding:5px',
frame: true, labelWidth: 80,
items: [
{ xtype: 'textfield', name: 'txt1', fieldLabel: 'user name' ,
allowBlank: false, anchor: '90%', enableKeyEvents: true,
listeners: {
keypress: function (field, e) {
if (e.getKey() == 13 ) {
this.nextSibling().focus();
}
} //keypress
}
},
{ xtype: 'textfield', inputType: 'password' , name: 'txt2', fieldLabel: 'User password',
allowBlank: false, anchor: '90%', enableKeyEvents: true,
listeners: {
keypress: function (field, e) {
if (e.getKey() == 13) {
this.nextSibling().focus();
}
} //keypress
}
},
{ xtype: 'textfield', name: 'txt3', fieldLabel: 'Verification Code',
allowBlank: false, anchor: '90%', mixLength: 6, maxLength: 6, enableKeyEvents: true,
listeners: {
keypress: function (field, e) {
if (e.getKey() == 13) {
this.ownerCt.submit();
}
} / /keypress
}
},
{ xtype: 'panel', height: 100, html: '
', border: false },
{ xtype: 'panel', height: 30, html: '
*If the picture is not clear, please click the picture to change the picture
', border: false }
], //items
buttons: [
{ text: 'OK', handler: function () { this.findParentByType('LoginFormPanel').submit(); }},
//This object-oriented programming, do not add scope: this here, otherwise the function will be assigned to the window
{ text: 'Reset', handler: function () { this.findParentByType('LoginFormPanel').form.reset(); } }
],
submit: function () {
if (this .getForm().isValid()) {
this.getForm().submit({
success: function (form, action) {
window.location = "main.htm";
},
failure: function (form, action) {
//Use the form parameter to access the form of the original submit
form.reset();
//Use action.result to access the result set
Ext.MessageBox.alert('Login failed', action.result.data);
}
})
}
}
});
The process has been written in the comments. If you have any questions, please discuss them below.