Roo/bootstrap/TextArea.js
[roojs1] / Roo / bootstrap / TextArea.js
1 /*
2  * - LGPL
3  *
4  * Input
5  * 
6  */
7
8 /**
9  * @class Roo.bootstrap.TextArea
10  * @extends Roo.bootstrap.Input
11  * Bootstrap TextArea class
12  * @cfg {Number} cols Specifies the visible width of a text area
13  * @cfg {Number} rows Specifies the visible number of lines in a text area
14  * @cfg {Number} readOnly Specifies that a text area should be read-only
15  * @cfg {string} wrap (soft|hard)Specifies how the text in a text area is to be wrapped when submitted in a form
16  * 
17  * @constructor
18  * Create a new TextArea
19  * @param {Object} config The config object
20  */
21
22 Roo.bootstrap.TextArea = function(config){
23     Roo.bootstrap.TextArea.superclass.constructor.call(this, config);
24    
25 };
26
27 Roo.extend(Roo.bootstrap.TextArea, Roo.bootstrap.Input,  {
28      
29     cols : false,
30     rows : 5,
31     readOnly : false,
32     warp : 'soft',
33     
34     getAutoCreate : function(){
35         
36         var parent = this.parent();
37         
38         var align = parent.labelAlign;
39         
40         var id = Roo.id();
41         
42         var cfg = {};
43         
44         var input =  {
45             tag: 'textarea',
46             id : id,
47             warp : this.warp,
48             rows : this.rows,
49             value : this.value,
50             cls : 'form-control',
51             placeholder : this.placeholder || '' 
52             
53         };
54         
55         if(this.cols){
56             input.cols = this.cols;
57         }
58         
59         if (this.readOnly) {
60             input.readonly = true;
61         }
62         
63         if (this.name) {
64             input.name = this.name;
65         }
66         
67         if (this.size) {
68             input.cls += ' input-' + this.size;
69         }
70         
71         var settings=this;
72         ['xs','sm','md','lg'].map(function(size){
73             if (settings[size]) {
74                 cfg.cls += ' col-' + size + '-' + settings[size];
75             }
76         });
77         
78         var inputblock = input;
79         
80         if (this.before || this.after) {
81             
82             inputblock = {
83                 cls : 'input-group',
84                 cn :  [] 
85             };
86             if (this.before) {
87                 inputblock.cn.push({
88                     tag :'span',
89                     cls : 'input-group-addon',
90                     html : this.before
91                 });
92             }
93             inputblock.cn.push(input);
94             if (this.after) {
95                 inputblock.cn.push({
96                     tag :'span',
97                     cls : 'input-group-addon',
98                     html : this.after
99                 });
100             }
101             
102         }
103         
104         if (align ==='left' && this.fieldLabel.length) {
105                 Roo.log("left and has label");
106                 cfg.cn = [
107                     
108                     {
109                         tag: 'label',
110                         'for' :  id,
111                         cls : 'control-label col-sm-' + this.labelWidth,
112                         html : this.fieldLabel
113                         
114                     },
115                     {
116                         cls : "col-sm-" + (12 - this.labelWidth), 
117                         cn: [
118                             inputblock
119                         ]
120                     }
121                     
122                 ];
123         } else if ( this.fieldLabel.length) {
124                 Roo.log(" label");
125                  cfg.cn = [
126                    
127                     {
128                         tag: 'label',
129                         //cls : 'input-group-addon',
130                         html : this.fieldLabel
131                         
132                     },
133                     
134                     inputblock
135                     
136                 ];
137
138         } else {
139             
140                    Roo.log(" no label && no align");
141                 cfg.cn = [
142                     
143                         inputblock
144                     
145                 ];
146                 
147                 
148         }
149         
150         if (this.disabled) {
151             input.disabled=true;
152         }
153         
154         return cfg;
155         
156     },
157     /**
158      * return the real textarea element.
159      */
160     inputEl: function ()
161     {
162         return this.el.select('textarea.form-control',true).first();
163     }
164 });
165
166