ExtJS Study Notes 3: Loading, submitting, and verifying forms
Load data
1. Easy-to-use method for setting form data:
formPanel.getForm().setValues([{id: 'FirstName', value: 'Joe'}]);
The id value is the name attribute value of field in form, and the value is the value to be assigned.
2. assign values through objects:
Ext.define('Request', {extend: 'Ext.data.Model',fields: ['FirstName','LastName','EmailAddress','TelNumberCode','TelNumber','RequestDetails','RequestType']});var requestModel = Ext.create('Request', requestData);formPanel.getForm().loadRecord(requestModel);
3. You can also load data from the server by using the load method:
formPanel.getForm().load({url: 'requestDetails.json'});
Submit Form
The simplest way is to call submit and submit it to the specified url.
var submitForm = function(){formPanel.getForm().submit({url: 'submit.url'});};var formPanel = Ext.create('Ext.form.Panel', {...buttons: [{text: 'Submit Form',handler: submitForm}],items: [...]});
You can also obtain an object from form and call ajax post to submit the object:
var record = formPanel.getForm().getRecord();
Verification Form
Verify by vtype:
{xtype: 'textfield',fieldLabel: 'Email Address',name: 'EmailAddress',labelAlign: 'top',cls: 'field-margin',columnWidth: 0.6,vtype: 'email'}