source:
trunk/workshop-routing-foss4g/web/ext/src/widgets/form/Label.js
@
81
Revision 76, 2.5 KB checked in by djay, 13 years ago (diff) | |
---|---|
|
Line | |
---|---|
1 | /*! |
2 | * Ext JS Library 3.4.0 |
3 | * Copyright(c) 2006-2011 Sencha Inc. |
4 | * licensing@sencha.com |
5 | * http://www.sencha.com/license |
6 | */ |
7 | /** |
8 | * @class Ext.form.Label |
9 | * @extends Ext.BoxComponent |
10 | * Basic Label field. |
11 | * @constructor |
12 | * Creates a new Label |
13 | * @param {Ext.Element/String/Object} config The configuration options. If an element is passed, it is set as the internal |
14 | * 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 |
15 | * and is used as the component id. Otherwise, it is assumed to be a standard config object and is applied to the component. |
16 | * @xtype label |
17 | */ |
18 | Ext.form.Label = Ext.extend(Ext.BoxComponent, { |
19 | /** |
20 | * @cfg {String} text The plain text to display within the label (defaults to ''). If you need to include HTML |
21 | * tags within the label's innerHTML, use the {@link #html} config instead. |
22 | */ |
23 | /** |
24 | * @cfg {String} forId The id of the input element to which this label will be bound via the standard HTML 'for' |
25 | * attribute. If not specified, the attribute will not be added to the label. |
26 | */ |
27 | /** |
28 | * @cfg {String} html An HTML fragment that will be used as the label's innerHTML (defaults to ''). |
29 | * Note that if {@link #text} is specified it will take precedence and this value will be ignored. |
30 | */ |
31 | |
32 | // private |
33 | onRender : function(ct, position){ |
34 | if(!this.el){ |
35 | this.el = document.createElement('label'); |
36 | this.el.id = this.getId(); |
37 | this.el.innerHTML = this.text ? Ext.util.Format.htmlEncode(this.text) : (this.html || ''); |
38 | if(this.forId){ |
39 | this.el.setAttribute('for', this.forId); |
40 | } |
41 | } |
42 | Ext.form.Label.superclass.onRender.call(this, ct, position); |
43 | }, |
44 | |
45 | /** |
46 | * Updates the label's innerHTML with the specified string. |
47 | * @param {String} text The new label text |
48 | * @param {Boolean} encode (optional) False to skip HTML-encoding the text when rendering it |
49 | * to the label (defaults to true which encodes the value). This might be useful if you want to include |
50 | * tags in the label's innerHTML rather than rendering them as string literals per the default logic. |
51 | * @return {Label} this |
52 | */ |
53 | setText : function(t, encode){ |
54 | var e = encode === false; |
55 | this[!e ? 'text' : 'html'] = t; |
56 | delete this[e ? 'text' : 'html']; |
57 | if(this.rendered){ |
58 | this.el.dom.innerHTML = encode !== false ? Ext.util.Format.htmlEncode(t) : t; |
59 | } |
60 | return this; |
61 | } |
62 | }); |
63 | |
64 | Ext.reg('label', Ext.form.Label); |
Note: See TracBrowser
for help on using the repository browser.