Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / examples / form / xml-form.js
index 9876a8f..be364c7 100644 (file)
-/*\r
- * Ext JS Library 2.2.1\r
- * Copyright(c) 2006-2009, Ext JS, LLC.\r
- * licensing@extjs.com\r
- * \r
- * http://extjs.com/license\r
- */\r
-\r
-Ext.onReady(function(){\r
-\r
-    Ext.QuickTips.init();\r
-\r
-    // turn on validation errors beside the field globally\r
-    Ext.form.Field.prototype.msgTarget = 'side';\r
-\r
-    var fs = new Ext.FormPanel({\r
-        frame: true,\r
-        title:'XML Form',\r
-        labelAlign: 'right',\r
-        labelWidth: 85,\r
-        width:340,\r
-        waitMsgTarget: true,\r
-\r
-        // configure how to read the XML Data\r
-        reader : new Ext.data.XmlReader({\r
-            record : 'contact',\r
-            success: '@success'\r
-        }, [\r
-            {name: 'first', mapping:'name/first'}, // custom mapping\r
-            {name: 'last', mapping:'name/last'},\r
-            'company', 'email', 'state',\r
-            {name: 'dob', type:'date', dateFormat:'m/d/Y'} // custom data types\r
-        ]),\r
-\r
-        // reusable eror reader class defined at the end of this file\r
-        errorReader: new Ext.form.XmlErrorReader(),\r
-\r
-        items: [\r
-            new Ext.form.FieldSet({\r
-                title: 'Contact Information',\r
-                autoHeight: true,\r
-                defaultType: 'textfield',\r
-                items: [{\r
-                        fieldLabel: 'First Name',\r
-                        name: 'first',\r
-                        width:190\r
-                    }, {\r
-                        fieldLabel: 'Last Name',\r
-                        name: 'last',\r
-                        width:190\r
-                    }, {\r
-                        fieldLabel: 'Company',\r
-                        name: 'company',\r
-                        width:190\r
-                    }, {\r
-                        fieldLabel: 'Email',\r
-                        name: 'email',\r
-                        vtype:'email',\r
-                        width:190\r
-                    },\r
-\r
-                    new Ext.form.ComboBox({\r
-                        fieldLabel: 'State',\r
-                        hiddenName:'state',\r
-                        store: new Ext.data.SimpleStore({\r
-                            fields: ['abbr', 'state'],\r
-                            data : Ext.exampledata.states // from states.js\r
-                        }),\r
-                        valueField:'abbr',\r
-                        displayField:'state',\r
-                        typeAhead: true,\r
-                        mode: 'local',\r
-                        triggerAction: 'all',\r
-                        emptyText:'Select a state...',\r
-                        selectOnFocus:true,\r
-                        width:190\r
-                    }),\r
-\r
-                    new Ext.form.DateField({\r
-                        fieldLabel: 'Date of Birth',\r
-                        name: 'dob',\r
-                        width:190,\r
-                        allowBlank:false\r
-                    })\r
-                ]\r
-            })\r
-        ]\r
-    });\r
-\r
-    // simple button add\r
-    fs.addButton('Load', function(){\r
-        fs.getForm().load({url:'xml-form.xml', waitMsg:'Loading'});\r
-    });\r
-\r
-    // explicit add\r
-    var submit = fs.addButton({\r
-        text: 'Submit',\r
-        disabled:true,\r
-        handler: function(){\r
-            fs.getForm().submit({url:'xml-errors.xml', waitMsg:'Saving Data...'});\r
-        }\r
-    });\r
-\r
-    fs.render('form-ct');\r
-\r
-    fs.on({\r
-        actioncomplete: function(form, action){\r
-            if(action.type == 'load'){\r
-                submit.enable();\r
-            }\r
-        }\r
-    });\r
-\r
-});\r
-\r
-// A reusable error reader class for XML forms\r
-Ext.form.XmlErrorReader = function(){\r
-    Ext.form.XmlErrorReader.superclass.constructor.call(this, {\r
-            record : 'field',\r
-            success: '@success'\r
-        }, [\r
-            'id', 'msg'\r
-        ]\r
-    );\r
-};\r
-Ext.extend(Ext.form.XmlErrorReader, Ext.data.XmlReader);
\ No newline at end of file
+/*
+
+This file is part of Ext JS 4
+
+Copyright (c) 2011 Sencha Inc
+
+Contact:  http://www.sencha.com/contact
+
+GNU General Public License Usage
+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.
+
+If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
+
+*/
+Ext.require([
+    'Ext.form.*',
+    'Ext.data.*'
+]);
+
+Ext.onReady(function(){
+
+    Ext.define('example.contact', {
+        extend: 'Ext.data.Model',
+        fields: [
+            {name: 'first', mapping: 'name > first'},
+            {name: 'last', mapping: 'name > last'},
+            'company', 'email', 'state',
+            {name: 'dob', type: 'date', dateFormat: 'm/d/Y'}
+        ]
+    });
+
+    Ext.define('example.fielderror', {
+        extend: 'Ext.data.Model',
+        fields: ['id', 'msg']
+    });
+
+    var formPanel = Ext.create('Ext.form.Panel', {
+        renderTo: 'form-ct',
+        frame: true,
+        title:'XML Form',
+        width: 340,
+        bodyPadding: 5,
+        waitMsgTarget: true,
+
+        fieldDefaults: {
+            labelAlign: 'right',
+            labelWidth: 85,
+            msgTarget: 'side'
+        },
+
+        // configure how to read the XML data
+        reader : Ext.create('Ext.data.reader.Xml', {
+            model: 'example.contact',
+            record : 'contact',
+            successProperty: '@success'
+        }),
+
+        // configure how to read the XML errors
+        errorReader: Ext.create('Ext.data.reader.Xml', {
+            model: 'example.fielderror',
+            record : 'field',
+            successProperty: '@success'
+        }),
+
+        items: [{
+            xtype: 'fieldset',
+            title: 'Contact Information',
+            defaultType: 'textfield',
+            defaults: {
+                width: 280
+            },
+            items: [{
+                    fieldLabel: 'First Name',
+                    emptyText: 'First Name',
+                    name: 'first'
+                }, {
+                    fieldLabel: 'Last Name',
+                    emptyText: 'Last Name',
+                    name: 'last'
+                }, {
+                    fieldLabel: 'Company',
+                    name: 'company'
+                }, {
+                    fieldLabel: 'Email',
+                    name: 'email',
+                    vtype:'email'
+                }, {
+                    xtype: 'combobox',
+                    fieldLabel: 'State',
+                    name: 'state',
+                    store: Ext.create('Ext.data.ArrayStore', {
+                        fields: ['abbr', 'state'],
+                        data : Ext.example.states // from states.js
+                    }),
+                    valueField: 'abbr',
+                    displayField: 'state',
+                    typeAhead: true,
+                    queryMode: 'local',
+                    emptyText: 'Select a state...'
+                }, {
+                    xtype: 'datefield',
+                    fieldLabel: 'Date of Birth',
+                    name: 'dob',
+                    allowBlank: false,
+                    maxValue: new Date()
+                }
+            ]
+        }],
+
+        buttons: [{
+            text: 'Load',
+            handler: function(){
+                formPanel.getForm().load({
+                    url: 'xml-form-data.xml',
+                    waitMsg: 'Loading...'
+                });
+            }
+        }, {
+            text: 'Submit',
+            disabled: true,
+            formBind: true,
+            handler: function(){
+                this.up('form').getForm().submit({
+                    url: 'xml-form-errors.xml',
+                    submitEmptyText: false,
+                    waitMsg: 'Saving Data...'
+                });
+            }
+        }]
+    });
+
+});
+