Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / src / form / field / Display.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 /**
16  * A display-only text field which is not validated and not submitted. This is useful for when you want to display a
17  * 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
18  * value. The value can be optionally {@link #htmlEncode HTML encoded} if it contains HTML markup that you do not want
19  * to be rendered.
20  *
21  * If you have more complex content, or need to include components within the displayed content, also consider using a
22  * {@link Ext.form.FieldContainer} instead.
23  *
24  * Example:
25  *
26  *     @example
27  *     Ext.create('Ext.form.Panel', {
28  *         renderTo: Ext.getBody(),
29  *         width: 175,
30  *         height: 120,
31  *         bodyPadding: 10,
32  *         title: 'Final Score',
33  *         items: [{
34  *             xtype: 'displayfield',
35  *             fieldLabel: 'Home',
36  *             name: 'home_score',
37  *             value: '10'
38  *         }, {
39  *             xtype: 'displayfield',
40  *             fieldLabel: 'Visitor',
41  *             name: 'visitor_score',
42  *             value: '11'
43  *         }],
44  *         buttons: [{
45  *             text: 'Update',
46  *         }]
47  *     });
48  */
49 Ext.define('Ext.form.field.Display', {
50     extend:'Ext.form.field.Base',
51     alias: 'widget.displayfield',
52     requires: ['Ext.util.Format', 'Ext.XTemplate'],
53     alternateClassName: ['Ext.form.DisplayField', 'Ext.form.Display'],
54     fieldSubTpl: [
55         '<div id="{id}" class="{fieldCls}"></div>',
56         {
57             compiled: true,
58             disableFormats: true
59         }
60     ],
61
62     /**
63      * @cfg {String} [fieldCls="x-form-display-field"]
64      * The default CSS class for the field.
65      */
66     fieldCls: Ext.baseCSSPrefix + 'form-display-field',
67
68     /**
69      * @cfg {Boolean} htmlEncode
70      * false to skip HTML-encoding the text when rendering it. This might be useful if you want to
71      * include tags in the field's innerHTML rather than rendering them as string literals per the default logic.
72      */
73     htmlEncode: false,
74
75     validateOnChange: false,
76
77     initEvents: Ext.emptyFn,
78
79     submitValue: false,
80
81     isValid: function() {
82         return true;
83     },
84
85     validate: function() {
86         return true;
87     },
88
89     getRawValue: function() {
90         return this.rawValue;
91     },
92
93     setRawValue: function(value) {
94         var me = this;
95         value = Ext.value(value, '');
96         me.rawValue = value;
97         if (me.rendered) {
98             me.inputEl.dom.innerHTML = me.htmlEncode ? Ext.util.Format.htmlEncode(value) : value;
99         }
100         return value;
101     },
102
103     // private
104     getContentTarget: function() {
105         return this.inputEl;
106     }
107
108     /**
109      * @cfg {String} inputType
110      * @hide
111      */
112     /**
113      * @cfg {Boolean} disabled
114      * @hide
115      */
116     /**
117      * @cfg {Boolean} readOnly
118      * @hide
119      */
120     /**
121      * @cfg {Boolean} validateOnChange
122      * @hide
123      */
124     /**
125      * @cfg {Number} checkChangeEvents
126      * @hide
127      */
128     /**
129      * @cfg {Number} checkChangeBuffer
130      * @hide
131      */
132 });
133