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