4 * Copyright(c) 2006-2007, Ext JS, LLC.
6 * Originally Released Under LGPL - original licence link has changed is not relivant.
9 * <script type="text/javascript">
13 * @class Roo.form.Layout
14 * @extends Roo.Component
15 * @children Roo.form.Column Roo.form.Row Roo.form.Field Roo.Button Roo.form.TextItem
16 * Creates a container for layout and rendering of fields in an {@link Roo.form.Form}.
18 * @param {Object} config Configuration options
20 Roo.form.Layout = function(config){
23 xitems = config.items;
26 Roo.form.Layout.superclass.constructor.call(this, config);
28 Roo.each(xitems, this.addxtype, this);
32 Roo.extend(Roo.form.Layout, Roo.Component, {
34 * @cfg {String/Object} autoCreate
35 * A DomHelper element spec used to autocreate the layout (defaults to {tag: 'div', cls: 'x-form-ct'})
38 * @cfg {String/Object/Function} style
39 * A style specification string, e.g. "width:100px", or object in the form {width:"100px"}, or
40 * a function which returns such a specification.
43 * @cfg {String} labelAlign
44 * Valid values are "left," "top" and "right" (defaults to "left")
47 * @cfg {Number} labelWidth
48 * Fixed width in pixels of all field labels (defaults to undefined)
51 * @cfg {Boolean} clear
52 * True to add a clearing element at the end of this layout, equivalent to CSS clear: both (defaults to true)
56 * @cfg {String} labelSeparator
57 * The separator to use after field labels (defaults to ':')
61 * @cfg {Boolean} hideLabels
62 * True to suppress the display of field labels in this layout (defaults to false)
67 defaultAutoCreate : {tag: 'div', cls: 'x-form-ct'},
72 onRender : function(ct, position){
73 if(this.el){ // from markup
74 this.el = Roo.get(this.el);
76 var cfg = this.getAutoCreate();
77 this.el = ct.createChild(cfg, position);
80 this.el.applyStyles(this.style);
83 this.el.addClass('x-form-label-'+this.labelAlign);
86 this.labelStyle = "display:none";
87 this.elementStyle = "padding-left:0;";
89 if(typeof this.labelWidth == 'number'){
90 this.labelStyle = "width:"+this.labelWidth+"px;";
91 this.elementStyle = "padding-left:"+((this.labelWidth+(typeof this.labelPad == 'number' ? this.labelPad : 5))+'px')+";";
93 if(this.labelAlign == 'top'){
94 this.labelStyle = "width:auto;";
95 this.elementStyle = "padding-left:0;";
98 var stack = this.stack;
99 var slen = stack.length;
102 var t = new Roo.Template(
103 '<div class="x-form-item {5}">',
104 '<label for="{0}" style="{2}">{1}{4}</label>',
105 '<div class="x-form-element" id="x-form-el-{0}" style="{3}">',
107 '</div><div class="x-form-clear-left"></div>'
109 t.disableFormats = true;
111 Roo.form.Layout.prototype.fieldTpl = t;
113 for(var i = 0; i < slen; i++) {
114 if(stack[i].isFormField){
115 this.renderField(stack[i]);
117 this.renderComponent(stack[i]);
122 this.el.createChild({cls:'x-form-clear'});
127 renderField : function(f){
128 f.fieldEl = Roo.get(this.fieldTpl.append(this.el, [
131 f.labelStyle||this.labelStyle||'', //2
132 this.elementStyle||'', //3
133 typeof f.labelSeparator == 'undefined' ? this.labelSeparator : f.labelSeparator, //4
134 f.itemCls||this.itemCls||'' //5
135 ], true).getPrevSibling());
139 renderComponent : function(c){
140 c.render(c.isLayout ? this.el : this.el.createChild());
143 * Adds a object form elements (using the xtype property as the factory method.)
144 * Valid xtypes are: TextField, TextArea .... Button, Layout, FieldSet, Column
145 * @param {Object} config
147 addxtype : function(o)
149 // create the lement.
151 var fe = Roo.factory(o, Roo.form);
152 this.form.allItems.push(fe);
155 if (fe.isFormField) {
156 this.form.items.add(fe);
164 * @class Roo.form.Column
165 * @extends Roo.form.Layout
166 * Creates a column container for layout and rendering of fields in an {@link Roo.form.Form}.
168 * @param {Object} config Configuration options
170 Roo.form.Column = function(config){
171 Roo.form.Column.superclass.constructor.call(this, config);
174 Roo.extend(Roo.form.Column, Roo.form.Layout, {
176 * @cfg {Number/String} width
177 * The fixed width of the column in pixels or CSS value (defaults to "auto")
180 * @cfg {String/Object} autoCreate
181 * A DomHelper element spec used to autocreate the column (defaults to {tag: 'div', cls: 'x-form-ct x-form-column'})
185 defaultAutoCreate : {tag: 'div', cls: 'x-form-ct x-form-column'},
188 onRender : function(ct, position){
189 Roo.form.Column.superclass.onRender.call(this, ct, position);
191 this.el.setWidth(this.width);
198 * @class Roo.form.Row
199 * @extends Roo.form.Layout
200 * @children Roo.form.Column Roo.form.Row Roo.form.Field Roo.Button Roo.form.TextItem
201 * Creates a row container for layout and rendering of fields in an {@link Roo.form.Form}.
203 * @param {Object} config Configuration options
207 Roo.form.Row = function(config){
208 Roo.form.Row.superclass.constructor.call(this, config);
211 Roo.extend(Roo.form.Row, Roo.form.Layout, {
213 * @cfg {Number/String} width
214 * The fixed width of the column in pixels or CSS value (defaults to "auto")
217 * @cfg {Number/String} height
218 * The fixed height of the column in pixels or CSS value (defaults to "auto")
220 defaultAutoCreate : {tag: 'div', cls: 'x-form-ct x-form-row'},
224 onRender : function(ct, position){
225 //console.log('row render');
227 var t = new Roo.Template(
228 '<div class="x-form-item {5}" style="float:left;width:{6}px">',
229 '<label for="{0}" style="{2}">{1}{4}</label>',
230 '<div class="x-form-element" id="x-form-el-{0}" style="{3}">',
234 t.disableFormats = true;
236 Roo.form.Layout.prototype.rowTpl = t;
238 this.fieldTpl = this.rowTpl;
240 //console.log('lw' + this.labelWidth +', la:' + this.labelAlign);
241 var labelWidth = 100;
243 if ((this.labelAlign != 'top')) {
244 if (typeof this.labelWidth == 'number') {
245 labelWidth = this.labelWidth
247 this.padWidth = 20 + labelWidth;
251 Roo.form.Column.superclass.onRender.call(this, ct, position);
253 this.el.setWidth(this.width);
256 this.el.setHeight(this.height);
261 renderField : function(f){
262 f.fieldEl = this.fieldTpl.append(this.el, [
264 f.labelStyle||this.labelStyle||'',
265 this.elementStyle||'',
266 typeof f.labelSeparator == 'undefined' ? this.labelSeparator : f.labelSeparator,
267 f.itemCls||this.itemCls||'',
268 f.width ? f.width + this.padWidth : 160 + this.padWidth
275 * @class Roo.form.FieldSet
276 * @extends Roo.form.Layout
277 * @children Roo.form.Column Roo.form.Row Roo.form.Field Roo.Button Roo.form.TextItem
278 * Creates a fieldset container for layout and rendering of fields in an {@link Roo.form.Form}.
280 * @param {Object} config Configuration options
282 Roo.form.FieldSet = function(config){
283 Roo.form.FieldSet.superclass.constructor.call(this, config);
286 Roo.extend(Roo.form.FieldSet, Roo.form.Layout, {
288 * @cfg {String} legend
289 * The text to display as the legend for the FieldSet (defaults to '')
292 * @cfg {String/Object} autoCreate
293 * A DomHelper element spec used to autocreate the fieldset (defaults to {tag: 'fieldset', cn: {tag:'legend'}})
297 defaultAutoCreate : {tag: 'fieldset', cn: {tag:'legend'}},
300 onRender : function(ct, position){
301 Roo.form.FieldSet.superclass.onRender.call(this, ct, position);
303 this.setLegend(this.legend);
308 setLegend : function(text){
310 this.el.child('legend').update(text);