Upgrade to ExtJS 4.0.2 - Released 06/09/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  * @class Ext.form.field.Display
17  * @extends Ext.form.field.Base
18  * <p>A display-only text field which is not validated and not submitted. This is useful for when you want
19  * to display a value from a form's {@link Ext.form.Basic#load loaded data} but do not want to allow the
20  * user to edit or submit that value. The value can be optionally {@link #htmlEncode HTML encoded} if it contains
21  * HTML markup that you do not want to be rendered.</p>
22  * <p>If you have more complex content, or need to include components within the displayed content, also
23  * consider using a {@link Ext.form.FieldContainer} instead.</p>
24  * {@img Ext.form.Display/Ext.form.Display.png Ext.form.Display component}
25  * <p>Example:</p>
26  * <pre><code>
27     Ext.create('Ext.form.Panel', {
28         width: 175,
29         height: 120,
30         bodyPadding: 10,
31         title: 'Final Score',
32         items: [{
33             xtype: 'displayfield',
34             fieldLabel: 'Home',
35             name: 'home_score',
36             value: '10'
37         }, {
38             xtype: 'displayfield',
39             fieldLabel: 'Visitor',
40             name: 'visitor_score',
41             value: '11'
42         }],
43         buttons: [{
44             text: 'Update',
45         }],
46         renderTo: Ext.getBody()
47     });
48 </code></pre>
49  */
50 Ext.define('Ext.form.field.Display', {
51     extend:'Ext.form.field.Base',
52     alias: 'widget.displayfield',
53     requires: ['Ext.util.Format', 'Ext.XTemplate'],
54     alternateClassName: ['Ext.form.DisplayField', 'Ext.form.Display'],
55     fieldSubTpl: [
56         '<div id="{id}" class="{fieldCls}"></div>',
57         {
58             compiled: true,
59             disableFormats: true
60         }
61     ],
62
63     /**
64      * @cfg {String} fieldCls The default CSS class for the field (defaults to <tt>"x-form-display-field"</tt>)
65      */
66     fieldCls: Ext.baseCSSPrefix + 'form-display-field',
67
68     /**
69      * @cfg {Boolean} htmlEncode <tt>false</tt> to skip HTML-encoding the text when rendering it (defaults to
70      * <tt>false</tt>). This might be useful if you want to include tags in the field's innerHTML rather than
71      * 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