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>
7 <body onload="prettyPrint();">
8 <pre class="prettyprint lang-js">Ext.ns("Ext.ux");
\r
10 <div id="cls-Ext.ux.FieldLabeler"></div>/**
\r
11 * @class Ext.ux.FieldLabeler
\r
12 * <p>A plugin for Field Components which renders standard Ext form wrapping and labels
\r
13 * round the Field at render time regardless of the layout of the Container.</p>
\r
18 plugins: [ Ext.ux.FieldLabeler ],
\r
19 triggerAction: 'all',
\r
20 fieldLabel: 'Select type',
\r
25 Ext.ux.FieldLabeler = (function(){
\r
27 // Pulls a named property down from the first ancestor Container it's found in
\r
28 function getParentProperty(propName) {
\r
29 for (var p = this.ownerCt; p; p = p.ownerCt) {
\r
38 // Add behaviour at important points in the Field's lifecycle.
\r
40 f.onRender = f.onRender.createSequence(this.onRender);
\r
41 f.onResize = f.onResize.createSequence(this.onResize);
\r
42 f.onDestroy = f.onDestroy.createSequence(this.onDestroy);
\r
45 onRender: function() {
\r
46 // Do nothing if being rendered by a form layout
\r
48 if (this.ownerCt.layout instanceof Ext.layout.FormLayout) {
\r
51 if (this.nextSibling()) {
\r
52 this.margins = '0 0 5 0';
\r
56 this.resizeEl = this.el.wrap({
\r
57 cls: 'x-form-element'
\r
59 this.positionEl = this.itemCt = this.resizeEl.wrap({
\r
62 this.actionMode = 'itemCt';
\r
64 // If we are hiding labels, then we're done!
\r
65 if (!Ext.isDefined(this.hideLabels)) {
\r
66 this.hideLabels = getParentProperty.call(this, "hideLabels");
\r
68 if (this.hideLabels) {
\r
69 this.resizeEl.setStyle('padding-left', '0px');
\r
73 // Collect info we need to render the label.
\r
74 if (!Ext.isDefined(this.labelSeparator)) {
\r
75 this.labelSeparator = getParentProperty.call(this, "labelSeparator");
\r
77 if (!Ext.isDefined(this.labelPad)) {
\r
78 this.labelPad = getParentProperty.call(this, "labelPad");
\r
80 if (!Ext.isDefined(this.labelAlign)) {
\r
81 this.labelAlign = getParentProperty.call(this, "labelAlign") || 'left';
\r
83 this.itemCt.addClass('x-form-label-' + this.labelAlign);
\r
85 if(this.labelAlign == 'top'){
\r
86 if (!this.labelWidth) {
\r
87 this.labelWidth = 'auto';
\r
89 this.resizeEl.setStyle('padding-left', '0px');
\r
91 if (!Ext.isDefined(this.labelWidth)) {
\r
92 this.labelWidth = getParentProperty.call(this, "labelWidth") || 100;
\r
94 this.resizeEl.setStyle('padding-left', (this.labelWidth + (this.labelPad || 5)) + 'px');
\r
95 this.labelWidth += 'px';
\r
98 this.label = this.itemCt.insertFirst({
\r
100 cls: 'x-form-item-label',
\r
102 width: this.labelWidth
\r
104 html: this.fieldLabel + (this.labelSeparator || ':')
\r
109 // Ensure the input field is sized to fit in the content area of the resizeEl (to the right of its padding-left)
\r
110 onResize: function() {
\r
111 this.el.setWidth(this.resizeEl.getWidth(true));
\r
112 if (this.el.dom.tagName.toLowerCase() == 'textarea') {
\r
113 var h = this.resizeEl.getHeight(true);
\r
114 if (!this.hideLabels && (this.labelAlign == 'top')) {
\r
115 h -= this.label.getHeight();
\r
117 this.el.setHeight(h);
\r
122 // Ensure that we clean up on destroy.
\r
123 onDestroy: function() {
\r
124 this.itemCt.remove();
\r