Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / examples / form / xml-form.js
1 /*
2
3 This file is part of Ext JS 4
4
5 Copyright (c) 2011 Sencha Inc
6
7 Contact:  http://www.sencha.com/contact
8
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file.  Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
11
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14 */
15 Ext.require([
16     'Ext.form.*',
17     'Ext.data.*'
18 ]);
19
20 Ext.onReady(function(){
21
22     Ext.define('example.contact', {
23         extend: 'Ext.data.Model',
24         fields: [
25             {name: 'first', mapping: 'name > first'},
26             {name: 'last', mapping: 'name > last'},
27             'company', 'email', 'state',
28             {name: 'dob', type: 'date', dateFormat: 'm/d/Y'}
29         ]
30     });
31
32     Ext.define('example.fielderror', {
33         extend: 'Ext.data.Model',
34         fields: ['id', 'msg']
35     });
36
37     var formPanel = Ext.create('Ext.form.Panel', {
38         renderTo: 'form-ct',
39         frame: true,
40         title:'XML Form',
41         width: 340,
42         bodyPadding: 5,
43         waitMsgTarget: true,
44
45         fieldDefaults: {
46             labelAlign: 'right',
47             labelWidth: 85,
48             msgTarget: 'side'
49         },
50
51         // configure how to read the XML data
52         reader : Ext.create('Ext.data.reader.Xml', {
53             model: 'example.contact',
54             record : 'contact',
55             successProperty: '@success'
56         }),
57
58         // configure how to read the XML errors
59         errorReader: Ext.create('Ext.data.reader.Xml', {
60             model: 'example.fielderror',
61             record : 'field',
62             successProperty: '@success'
63         }),
64
65         items: [{
66             xtype: 'fieldset',
67             title: 'Contact Information',
68             defaultType: 'textfield',
69             defaults: {
70                 width: 280
71             },
72             items: [{
73                     fieldLabel: 'First Name',
74                     emptyText: 'First Name',
75                     name: 'first'
76                 }, {
77                     fieldLabel: 'Last Name',
78                     emptyText: 'Last Name',
79                     name: 'last'
80                 }, {
81                     fieldLabel: 'Company',
82                     name: 'company'
83                 }, {
84                     fieldLabel: 'Email',
85                     name: 'email',
86                     vtype:'email'
87                 }, {
88                     xtype: 'combobox',
89                     fieldLabel: 'State',
90                     name: 'state',
91                     store: Ext.create('Ext.data.ArrayStore', {
92                         fields: ['abbr', 'state'],
93                         data : Ext.example.states // from states.js
94                     }),
95                     valueField: 'abbr',
96                     displayField: 'state',
97                     typeAhead: true,
98                     queryMode: 'local',
99                     emptyText: 'Select a state...'
100                 }, {
101                     xtype: 'datefield',
102                     fieldLabel: 'Date of Birth',
103                     name: 'dob',
104                     allowBlank: false
105                 }
106             ]
107         }],
108
109         buttons: [{
110             text: 'Load',
111             handler: function(){
112                 formPanel.getForm().load({
113                     url: 'xml-form-data.xml',
114                     waitMsg: 'Loading...'
115                 });
116             }
117         }, {
118             text: 'Submit',
119             disabled: true,
120             formBind: true,
121             handler: function(){
122                 this.up('form').getForm().submit({
123                     url: 'xml-form-errors.xml',
124                     submitEmptyText: false,
125                     waitMsg: 'Saving Data...'
126                 });
127             }
128         }]
129     });
130
131 });
132