3 * Copyright(c) 2006-2009 Ext JS, LLC
5 * http://www.extjs.com/license
10 * @class Ext.ux.FieldLabeler
\r
11 * <p>A plugin for Field Components which renders standard Ext form wrapping and labels
\r
12 * round the Field at render time regardless of the layout of the Container.</p>
\r
17 plugins: [ Ext.ux.FieldLabeler ],
\r
18 triggerAction: 'all',
\r
19 fieldLabel: 'Select type',
\r
24 Ext.ux.FieldLabeler = (function(){
\r
26 // Pulls a named property down from the first ancestor Container it's found in
\r
27 function getParentProperty(propName) {
\r
28 for (var p = this.ownerCt; p; p = p.ownerCt) {
\r
37 // Add behaviour at important points in the Field's lifecycle.
\r
39 f.onRender = f.onRender.createSequence(this.onRender);
\r
40 f.onResize = f.onResize.createSequence(this.onResize);
\r
41 f.onDestroy = f.onDestroy.createSequence(this.onDestroy);
\r
44 onRender: function() {
\r
45 // Do nothing if being rendered by a form layout
\r
47 if (this.ownerCt.layout instanceof Ext.layout.FormLayout) {
\r
50 if (this.nextSibling()) {
\r
51 this.margins = '0 0 5 0';
\r
55 this.resizeEl = this.el.wrap({
\r
56 cls: 'x-form-element'
\r
58 this.positionEl = this.itemCt = this.resizeEl.wrap({
\r
61 this.actionMode = 'itemCt';
\r
63 // If we are hiding labels, then we're done!
\r
64 if (!Ext.isDefined(this.hideLabels)) {
\r
65 this.hideLabels = getParentProperty.call(this, "hideLabels");
\r
67 if (this.hideLabels) {
\r
68 this.resizeEl.setStyle('padding-left', '0px');
\r
72 // Collect info we need to render the label.
\r
73 if (!Ext.isDefined(this.labelSeparator)) {
\r
74 this.labelSeparator = getParentProperty.call(this, "labelSeparator");
\r
76 if (!Ext.isDefined(this.labelPad)) {
\r
77 this.labelPad = getParentProperty.call(this, "labelPad");
\r
79 if (!Ext.isDefined(this.labelAlign)) {
\r
80 this.labelAlign = getParentProperty.call(this, "labelAlign") || 'left';
\r
82 this.itemCt.addClass('x-form-label-' + this.labelAlign);
\r
84 if(this.labelAlign == 'top'){
\r
85 if (!this.labelWidth) {
\r
86 this.labelWidth = 'auto';
\r
88 this.resizeEl.setStyle('padding-left', '0px');
\r
90 if (!Ext.isDefined(this.labelWidth)) {
\r
91 this.labelWidth = getParentProperty.call(this, "labelWidth") || 100;
\r
93 this.resizeEl.setStyle('padding-left', (this.labelWidth + (this.labelPad || 5)) + 'px');
\r
94 this.labelWidth += 'px';
\r
97 this.label = this.itemCt.insertFirst({
\r
99 cls: 'x-form-item-label',
\r
101 width: this.labelWidth
\r
103 html: this.fieldLabel + (this.labelSeparator || ':')
\r
108 // Ensure the input field is sized to fit in the content area of the resizeEl (to the right of its padding-left)
\r
109 onResize: function() {
\r
110 this.el.setWidth(this.resizeEl.getWidth(true));
\r
111 if (this.el.dom.tagName.toLowerCase() == 'textarea') {
\r
112 var h = this.resizeEl.getHeight(true);
\r
113 if (!this.hideLabels && (this.labelAlign == 'top')) {
\r
114 h -= this.label.getHeight();
\r
116 this.el.setHeight(h);
\r
121 // Ensure that we clean up on destroy.
\r
122 onDestroy: function() {
\r
123 this.itemCt.remove();
\r