Upgrade to ExtJS 3.0.0 - Released 07/06/2009
[extjs.git] / docs / source / Label.html
1 <html>\r
2 <head>\r
3   <title>The source code</title>\r
4     <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />\r
5     <script type="text/javascript" src="../resources/prettify/prettify.js"></script>\r
6 </head>\r
7 <body  onload="prettyPrint();">\r
8     <pre class="prettyprint lang-js"><div id="cls-Ext.form.Label"></div>/**
9  * @class Ext.form.Label
10  * @extends Ext.BoxComponent
11  * Basic Label field.
12  * @constructor
13  * Creates a new Label
14  * @param {Ext.Element/String/Object} config The configuration options.  If an element is passed, it is set as the internal
15  * element and its id used as the component id.  If a string is passed, it is assumed to be the id of an existing element
16  * and is used as the component id.  Otherwise, it is assumed to be a standard config object and is applied to the component.
17  * @xtype label
18  */
19 Ext.form.Label = Ext.extend(Ext.BoxComponent, {
20     <div id="cfg-Ext.form.Label-text"></div>/**
21      * @cfg {String} text The plain text to display within the label (defaults to ''). If you need to include HTML
22      * tags within the label's innerHTML, use the {@link #html} config instead.
23      */
24     <div id="cfg-Ext.form.Label-forId"></div>/**
25      * @cfg {String} forId The id of the input element to which this label will be bound via the standard HTML 'for'
26      * attribute. If not specified, the attribute will not be added to the label.
27      */
28     <div id="cfg-Ext.form.Label-html"></div>/**
29      * @cfg {String} html An HTML fragment that will be used as the label's innerHTML (defaults to '').
30      * Note that if {@link #text} is specified it will take precedence and this value will be ignored.
31      */
32
33     // private
34     onRender : function(ct, position){
35         if(!this.el){
36             this.el = document.createElement('label');
37             this.el.id = this.getId();
38             this.el.innerHTML = this.text ? Ext.util.Format.htmlEncode(this.text) : (this.html || '');
39             if(this.forId){
40                 this.el.setAttribute('for', this.forId);
41             }
42         }
43         Ext.form.Label.superclass.onRender.call(this, ct, position);
44     },
45
46     <div id="method-Ext.form.Label-setText"></div>/**
47      * Updates the label's innerHTML with the specified string.
48      * @param {String} text The new label text
49      * @param {Boolean} encode (optional) False to skip HTML-encoding the text when rendering it
50      * to the label (defaults to true which encodes the value). This might be useful if you want to include
51      * tags in the label's innerHTML rather than rendering them as string literals per the default logic.
52      * @return {Label} this
53      */
54     setText : function(t, encode){
55         var e = encode === false;
56         this[!e ? 'text' : 'html'] = t;
57         delete this[e ? 'text' : 'html'];
58         if(this.rendered){
59             this.el.dom.innerHTML = encode !== false ? Ext.util.Format.htmlEncode(t) : t;
60         }
61         return this;
62     }
63 });
64
65 Ext.reg('label', Ext.form.Label);</pre>    \r
66 </body>\r
67 </html>