3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
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.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * @docauthor Jason Johnston <jason@sencha.com>
18 * Produces a standalone `<label />` element which can be inserted into a form and be associated with a field
19 * in that form using the {@link #forId} property.
21 * **NOTE:** in most cases it will be more appropriate to use the {@link Ext.form.Labelable#fieldLabel fieldLabel}
22 * and associated config properties ({@link Ext.form.Labelable#labelAlign}, {@link Ext.form.Labelable#labelWidth},
23 * etc.) in field components themselves, as that allows labels to be uniformly sized throughout the form.
24 * Ext.form.Label should only be used when your layout can not be achieved with the standard
25 * {@link Ext.form.Labelable field layout}.
27 * You will likely be associating the label with a field component that extends {@link Ext.form.field.Base}, so
28 * you should make sure the {@link #forId} is set to the same value as the {@link Ext.form.field.Base#inputId inputId}
31 * The label's text can be set using either the {@link #text} or {@link #html} configuration properties; the
32 * difference between the two is that the former will automatically escape HTML characters when rendering, while
33 * the latter will not.
37 * This example creates a Label after its associated Text field, an arrangement that cannot currently
38 * be achieved using the standard Field layout's labelAlign.
41 * Ext.create('Ext.form.Panel', {
42 * title: 'Field with Label',
45 * renderTo: Ext.getBody(),
57 * text: 'My Awesome Field',
62 Ext.define('Ext.form.Label', {
63 extend:'Ext.Component',
64 alias: 'widget.label',
65 requires: ['Ext.util.Format'],
68 * @cfg {String} [text='']
69 * The plain text to display within the label. If you need to include HTML
70 * tags within the label's innerHTML, use the {@link #html} config instead.
74 * The id of the input element to which this label will be bound via the standard HTML 'for'
75 * attribute. If not specified, the attribute will not be added to the label. In most cases you will be
76 * associating the label with a {@link Ext.form.field.Base} component, so you should make sure this matches
77 * the {@link Ext.form.field.Base#inputId inputId} of that field.
80 * @cfg {String} [html='']
81 * An HTML fragment that will be used as the label's innerHTML.
82 * Note that if {@link #text} is specified it will take precedence and this value will be ignored.
86 getElConfig: function(){
91 htmlFor: me.forId || '',
92 html: me.text ? Ext.util.Format.htmlEncode(me.text) : (me.html || '')
97 * Updates the label's innerHTML with the specified string.
98 * @param {String} text The new label text
99 * @param {Boolean} [encode=true] False to skip HTML-encoding the text when rendering it
100 * to the label. This might be useful if you want to include tags in the label's innerHTML rather
101 * than rendering them as string literals per the default logic.
102 * @return {Ext.form.Label} this
104 setText : function(text, encode){
107 encode = encode !== false;
117 me.el.dom.innerHTML = encode !== false ? Ext.util.Format.htmlEncode(text) : text;