3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js">Ext.ns('App', 'App.user');
9 <div id="cls-App.user.FormPanel"></div>/**
10 * @class App.user.FormPanel
11 * A typical FormPanel extension
13 App.user.Form = Ext.extend(Ext.form.FormPanel, {
14 renderTo: 'user-form',
18 title: 'User -- All fields are required',
21 defaultType: 'textfield',
26 // private A pointer to the currently loaded record
29 <div id="method-App.user.FormPanel-initComponent"></div>/**
33 initComponent : function() {
34 // build the form-fields. Always a good idea to defer form-building to a method so that this class can
35 // be over-ridden to provide different form-fields
36 this.items = this.buildForm();
39 this.buttons = this.buildUI();
41 // add a create event for convenience in our application-code.
43 <div id="event-App.user.FormPanel-create"></div>/**
45 * Fires when user clicks [create] button
46 * @param {FormPanel} this
47 * @param {Object} values, the Form's values object
53 App.user.Form.superclass.initComponent.call(this);
60 buildForm : function() {
62 {fieldLabel: 'Email', name: 'email', allowBlank: false, vtype: 'email'},
63 {fieldLabel: 'First', name: 'first', allowBlank: false},
64 {fieldLabel: 'Last', name: 'last', allowBlank: false}
76 handler: this.onUpdate,
80 iconCls: 'silk-user-add',
81 handler: this.onCreate,
85 handler: function(btn, ev){
86 this.getForm().reset();
92 <div id="method-App.user.FormPanel-loadRecord"></div>/**
96 loadRecord : function(rec) {
98 this.getForm().loadRecord(rec);
101 <div id="method-App.user.FormPanel-onUpdate"></div>/**
104 onUpdate : function(btn, ev) {
105 if (this.record == null) {
108 if (!this.getForm().isValid()) {
109 App.setAlert(false, "Form is invalid.");
112 this.getForm().updateRecord(this.record);
115 <div id="method-App.user.FormPanel-onCreate"></div>/**
118 onCreate : function(btn, ev) {
119 if (!this.getForm().isValid()) {
120 App.setAlert(false, "Form is invalid");
123 this.fireEvent('create', this, this.getForm().getValues());
124 this.getForm().reset();
127 <div id="method-App.user.FormPanel-onReset"></div>/**
130 onReset : function(btn, ev) {
131 this.fireEvent('update', this, this.getForm().getValues());
132 this.getForm().reset();