]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | /**\r |
2 | * A display-only text field which is not validated and not submitted. This is useful for when you want to display a\r | |
3 | * value from a form's {@link Ext.form.Basic#load loaded data} but do not want to allow the user to edit or submit that\r | |
4 | * value. The value can be optionally {@link #htmlEncode HTML encoded} if it contains HTML markup that you do not want\r | |
5 | * to be rendered.\r | |
6 | *\r | |
7 | * If you have more complex content, or need to include components within the displayed content, also consider using a\r | |
8 | * {@link Ext.form.FieldContainer} instead.\r | |
9 | *\r | |
10 | * Example:\r | |
11 | *\r | |
12 | * @example\r | |
13 | * Ext.create('Ext.form.Panel', {\r | |
14 | * renderTo: Ext.getBody(),\r | |
15 | * width: 175,\r | |
16 | * height: 150,\r | |
17 | * bodyPadding: 10,\r | |
18 | * title: 'Final Score',\r | |
19 | * items: [{\r | |
20 | * xtype: 'displayfield',\r | |
21 | * fieldLabel: 'Home',\r | |
22 | * name: 'home_score',\r | |
23 | * value: '10'\r | |
24 | * }, {\r | |
25 | * xtype: 'displayfield',\r | |
26 | * fieldLabel: 'Visitor',\r | |
27 | * name: 'visitor_score',\r | |
28 | * value: '11'\r | |
29 | * }],\r | |
30 | * buttons: [{\r | |
31 | * text: 'Update'\r | |
32 | * }]\r | |
33 | * });\r | |
34 | */\r | |
35 | Ext.define('Ext.form.field.Display', {\r | |
36 | extend:'Ext.form.field.Base',\r | |
37 | alias: 'widget.displayfield',\r | |
38 | requires: ['Ext.util.Format', 'Ext.XTemplate'],\r | |
39 | alternateClassName: ['Ext.form.DisplayField', 'Ext.form.Display'],\r | |
40 | \r | |
41 | fieldSubTpl: [\r | |
42 | '<div id="{id}" data-ref="inputEl" tabindex="-1" role="textbox" aria-readonly="true"',\r | |
43 | ' aria-labelledby="{cmpId}-labelEl" {inputAttrTpl}',\r | |
44 | '<tpl if="fieldStyle"> style="{fieldStyle}"</tpl>', \r | |
45 | ' class="{fieldCls} {fieldCls}-{ui}">{value}</div>',\r | |
46 | {\r | |
47 | compiled: true,\r | |
48 | disableFormats: true\r | |
49 | }\r | |
50 | ],\r | |
51 | \r | |
52 | // We have the ARIA markup pre-rendered so we don't want it to be applied\r | |
53 | ariaRole: undefined,\r | |
54 | \r | |
55 | focusable: false,\r | |
56 | \r | |
57 | /**\r | |
58 | * @cfg {Boolean} readOnly\r | |
59 | * @private\r | |
60 | */\r | |
61 | readOnly: true,\r | |
62 | \r | |
63 | /**\r | |
64 | * @cfg {String} [fieldCls="x-form-display-field"]\r | |
65 | * The default CSS class for the field.\r | |
66 | */\r | |
67 | fieldCls: Ext.baseCSSPrefix + 'form-display-field',\r | |
68 | \r | |
69 | fieldBodyCls: Ext.baseCSSPrefix + 'form-display-field-body',\r | |
70 | \r | |
71 | /**\r | |
72 | * @cfg {Boolean} htmlEncode\r | |
73 | * True to escape HTML in text when rendering it.\r | |
74 | */\r | |
75 | htmlEncode: false,\r | |
76 | \r | |
77 | /**\r | |
78 | * @cfg {Function} renderer\r | |
79 | * A function to transform the raw value for display in the field.\r | |
80 | * \r | |
81 | * Ext.create('Ext.form.Panel', {\r | |
82 | * renderTo: document.body,\r | |
83 | * width: 175,\r | |
84 | * bodyPadding: 10,\r | |
85 | * title: 'Final Score',\r | |
86 | * items: [{\r | |
87 | * xtype: 'displayfield',\r | |
88 | * fieldLabel: 'Grade',\r | |
89 | * name: 'final_grade',\r | |
90 | * value: 68,\r | |
91 | * renderer: function (value, field) {\r | |
92 | * var color = (value < 70) ? 'red' : 'black';\r | |
93 | * return '<span style="color:' + color + ';">' + value + '</span>';\r | |
94 | * }\r | |
95 | * }]\r | |
96 | * });\r | |
97 | * \r | |
98 | * @param {Object} value The raw field {@link #value}\r | |
99 | * @param {Ext.form.field.Display} field The display field\r | |
100 | * @return {String} displayValue The HTML string to be rendered\r | |
101 | */\r | |
102 | \r | |
103 | /**\r | |
104 | * @cfg {Object} scope\r | |
105 | * The scope to execute the {@link #renderer} function. Defaults to this.\r | |
106 | */\r | |
107 | \r | |
108 | noWrap: false,\r | |
109 | \r | |
110 | /**\r | |
111 | * @cfg {Boolean} validateOnChange\r | |
112 | * @private\r | |
113 | */\r | |
114 | validateOnChange: false,\r | |
115 | \r | |
116 | initEvents: Ext.emptyFn,\r | |
117 | \r | |
118 | submitValue: false,\r | |
119 | \r | |
120 | getValue: function() {\r | |
121 | return this.value;\r | |
122 | },\r | |
123 | \r | |
124 | valueToRaw: function(value) {\r | |
125 | if (value || value === 0 || value === false) {\r | |
126 | return value;\r | |
127 | } else {\r | |
128 | return '';\r | |
129 | }\r | |
130 | },\r | |
131 | \r | |
132 | isDirty: function(){\r | |
133 | return false;\r | |
134 | },\r | |
135 | \r | |
136 | isValid: Ext.returnTrue,\r | |
137 | \r | |
138 | validate: Ext.returnTrue,\r | |
139 | \r | |
140 | getRawValue: function() {\r | |
141 | return this.rawValue;\r | |
142 | },\r | |
143 | \r | |
144 | setRawValue: function(value) {\r | |
145 | var me = this;\r | |
146 | \r | |
147 | value = Ext.valueFrom(value, '');\r | |
148 | me.rawValue = value;\r | |
149 | if (me.rendered) {\r | |
150 | me.inputEl.dom.innerHTML = me.getDisplayValue();\r | |
151 | me.updateLayout();\r | |
152 | }\r | |
153 | return value;\r | |
154 | },\r | |
155 | \r | |
156 | /**\r | |
157 | * @private\r | |
158 | * Format the value to display.\r | |
159 | */\r | |
160 | getDisplayValue: function() {\r | |
161 | var me = this,\r | |
162 | value = this.getRawValue(),\r | |
163 | display;\r | |
164 | if (me.renderer) {\r | |
165 | display = me.renderer.call(me.scope || me, value, me);\r | |
166 | } else {\r | |
167 | display = me.htmlEncode ? Ext.util.Format.htmlEncode(value) : value;\r | |
168 | }\r | |
169 | return display;\r | |
170 | },\r | |
171 | \r | |
172 | getSubTplData: function(fieldData) {\r | |
173 | var ret = this.callParent(arguments);\r | |
174 | \r | |
175 | ret.value = this.getDisplayValue();\r | |
176 | \r | |
177 | return ret;\r | |
178 | }\r | |
179 | \r | |
180 | /**\r | |
181 | * @cfg {String} inputType\r | |
182 | * @private\r | |
183 | */\r | |
184 | /**\r | |
185 | * @cfg {Boolean} disabled\r | |
186 | * @private\r | |
187 | */\r | |
188 | /**\r | |
189 | * @cfg {Number} checkChangeEvents\r | |
190 | * @private\r | |
191 | */\r | |
192 | /**\r | |
193 | * @cfg {Number} checkChangeBuffer\r | |
194 | * @private\r | |
195 | */\r | |
196 | });\r |