Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / examples / simple-widgets / editor.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.Editor',
17     'Ext.form.Panel',
18     'Ext.form.field.ComboBox',
19     'Ext.form.field.Date',
20     'Ext.data.Store',
21     'Ext.data.proxy.Ajax',
22     'Ext.data.reader.Json',
23     'Ext.data.writer.Json'
24 ]);
25
26 Ext.onReady(function(){
27     Ext.create('Ext.form.Panel', {
28         renderTo: 'container',
29         width: 700,
30         height: 400,
31         title: 'User Details',
32         defaultType: 'textfield',
33         bodyStyle: 'padding: 10px;',
34         labelWidth: 90,
35         items: [{
36             fieldLabel: 'First Name',
37             name: 'firstname'
38         }, {
39             fieldLabel: 'Middle Name',
40             name: 'middlename'
41         }, {
42             fieldLabel: 'Last Name',
43             name: 'lastname'
44         }, {
45             xtype: 'datefield',
46             name: 'dob',
47             fieldLabel: 'D.O.B'
48         }],
49         listeners: {
50             afterrender: function(form){
51                 var cfg = {
52                     shadow: false,
53                     completeOnEnter: true,
54                     cancelOnEsc: true,
55                     updateEl: true,
56                     ignoreNoChange: true
57                 }, height = form.child('textfield').getHeight();
58
59                 var labelEditor = Ext.create('Ext.Editor', Ext.apply({
60                     width: 100,
61                     height: height,
62                     offsets: [0, 2],
63                     alignment: 'l-l',
64                     listeners: {
65                         beforecomplete: function(ed, value){
66                             if (value.charAt(value.length - 1) != ':') {
67                                 ed.setValue(ed.getValue() + ':');
68                             }
69                             return true;
70                         }
71                     },
72                     field: {
73                         name: 'labelfield',
74                         allowBlank: false,
75                         xtype: 'textfield',
76                         width: 90,
77                         selectOnFocus: true
78                     }
79                 }, cfg));
80                 form.body.on('dblclick', function(e, t){
81                     labelEditor.startEdit(t);
82                     // Manually focus, since clicking on the label will focus the text field
83                     labelEditor.field.focus(50, true);
84                 }, null, {
85                     delegate: 'label.x-form-item-label'
86                 });
87
88                 var titleEditor = Ext.create('Ext.Editor', Ext.apply({
89                     alignment: 'bl-bl?',
90                     offsets: [0, 10],
91                     field: {
92                         width: 130,
93                         xtype: 'combo',
94                         editable: false,
95                         forceSelection: true,
96                         queryMode: 'local',
97                         displayField: 'text',
98                         valueField: 'text',
99                         store: {
100                             fields: ['text'],
101                             data: [{
102                                 text: 'User Details'
103                             },{
104                                 text: 'Developer Detail'
105                             },{
106                                 text: 'Manager Details'
107                             }]
108                         }
109                     }
110                 }, cfg));
111
112                 form.header.titleCmp.textEl.on('dblclick', function(e, t){
113                     titleEditor.startEdit(t);
114                 });
115             }
116         }
117     });
118 });
119