4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-form-Label'>/**
19 </span> * @class Ext.form.Label
20 * @extends Ext.Component
22 Produces a standalone `<label />` element which can be inserted into a form and be associated with a field
23 in that form using the {@link #forId} property.
25 **NOTE:** in most cases it will be more appropriate to use the {@link Ext.form.Labelable#fieldLabel fieldLabel}
26 and associated config properties ({@link Ext.form.Labelable#labelAlign}, {@link Ext.form.Labelable#labelWidth},
27 etc.) in field components themselves, as that allows labels to be uniformly sized throughout the form.
28 Ext.form.Label should only be used when your layout can not be achieved with the standard
29 {@link Ext.form.Labelable field layout}.
31 You will likely be associating the label with a field component that extends {@link Ext.form.field.Base}, so
32 you should make sure the {@link #forId} is set to the same value as the {@link Ext.form.field.Base#inputId inputId}
35 The label's text can be set using either the {@link #text} or {@link #html} configuration properties; the
36 difference between the two is that the former will automatically escape HTML characters when rendering, while
38 {@img Ext.form.Label/Ext.form.Label.png Ext.form.Label component}
41 This example creates a Label after its associated Text field, an arrangement that cannot currently
42 be achieved using the standard Field layout's labelAlign.
44 Ext.create('Ext.form.Panel', {
45 title: 'Field with Label',
48 renderTo: Ext.getBody(),
60 text: 'My Awesome Field',
66 * @docauthor Jason Johnston <jason@sencha.com>
68 Ext.define('Ext.form.Label', {
69 extend:'Ext.Component',
70 alias: 'widget.label',
71 requires: ['Ext.util.Format'],
73 <span id='Ext-form-Label-cfg-text'> /**
74 </span> * @cfg {String} text The plain text to display within the label (defaults to ''). If you need to include HTML
75 * tags within the label's innerHTML, use the {@link #html} config instead.
77 <span id='Ext-form-Label-cfg-forId'> /**
78 </span> * @cfg {String} forId The id of the input element to which this label will be bound via the standard HTML 'for'
79 * attribute. If not specified, the attribute will not be added to the label. In most cases you will be
80 * associating the label with a {@link Ext.form.field.Base} component, so you should make sure this matches
81 * the {@link Ext.form.field.Base#inputId inputId} of that field.
83 <span id='Ext-form-Label-cfg-html'> /**
84 </span> * @cfg {String} html An HTML fragment that will be used as the label's innerHTML (defaults to '').
85 * Note that if {@link #text} is specified it will take precedence and this value will be ignored.
89 getElConfig: function(){
94 htmlFor: me.forId || '',
95 html: me.text ? Ext.util.Format.htmlEncode(me.text) : (me.html || '')
99 <span id='Ext-form-Label-method-setText'> /**
100 </span> * Updates the label's innerHTML with the specified string.
101 * @param {String} text The new label text
102 * @param {Boolean} encode (optional) False to skip HTML-encoding the text when rendering it
103 * to the label (defaults to true which encodes the value). This might be useful if you want to include
104 * tags in the label's innerHTML rather than rendering them as string literals per the default logic.
105 * @return {Label} this
107 setText : function(text, encode){
110 encode = encode !== false;
120 me.el.dom.innerHTML = encode !== false ? Ext.util.Format.htmlEncode(text) : text;