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 {string} wrap (soft|hard)Specifies how the text in a text area is to be wrapped when submitted in a form
15  * @cfg {string} resize (none|both|horizontal|vertical|inherit|initial)
16  * @cfg {string} html text
17  * 
18  * @constructor
19  * Create a new TextArea
20  * @param {Object} config The config object
21  */
22
23 Roo.bootstrap.TextArea = function(config){
24     Roo.bootstrap.TextArea.superclass.constructor.call(this, config);
25    
26 };
27
28 Roo.extend(Roo.bootstrap.TextArea, Roo.bootstrap.Input,  {
29      
30     cols : false,
31     rows : 5,
32     readOnly : false,
33     warp : 'soft',
34     resize : false,
35     value: false,
36     html: false,
37     
38     getAutoCreate : function(){
39         
40         var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
41         
42         var id = Roo.id();
43         
44         var cfg = {};
45         
46         var input =  {
47             tag: 'textarea',
48             id : id,
49             warp : this.warp,
50             rows : this.rows,
51             value : this.value || '',
52             html: this.html || '',
53             cls : 'form-control',
54             placeholder : this.placeholder || '' 
55             
56         };
57         
58         if(this.maxLength && this.maxLength != Number.MAX_VALUE){
59             input.maxLength = this.maxLength;
60         }
61         
62         if(this.resize){
63             input.style = (typeof(input.style) == 'undefined') ? 'resize:' + this.resize : input.style + 'resize:' + this.resize;
64         }
65         
66         if(this.cols){
67             input.cols = this.cols;
68         }
69         
70         if (this.readOnly) {
71             input.readonly = true;
72         }
73         
74         if (this.name) {
75             input.name = this.name;
76         }
77         
78         if (this.size) {
79             input.cls = (typeof(input.cls) == 'undefined') ? 'input-' + this.size : input.cls + ' input-' + this.size;
80         }
81         
82         var settings=this;
83         ['xs','sm','md','lg'].map(function(size){
84             if (settings[size]) {
85                 cfg.cls += ' col-' + size + '-' + settings[size];
86             }
87         });
88         
89         var inputblock = input;
90         
91         if(this.hasFeedback){
92             
93             var feedback = {
94                 tag: 'span',
95                 cls: 'glyphicon form-control-feedback'
96             };
97
98             inputblock = {
99                 cls : 'has-feedback',
100                 cn :  [
101                     input,
102                     feedback
103                 ] 
104             };  
105         }
106         
107         
108         if (this.before || this.after) {
109             
110             inputblock = {
111                 cls : 'input-group',
112                 cn :  [] 
113             };
114             if (this.before) {
115                 inputblock.cn.push({
116                     tag :'span',
117                     cls : 'input-group-addon',
118                     html : this.before
119                 });
120             }
121             
122             inputblock.cn.push(input);
123             
124             if (this.after) {
125                 inputblock.cn.push({
126                     tag :'span',
127                     cls : 'input-group-addon',
128                     html : this.after
129                 });
130             }
131             
132         }
133         
134         if (align ==='left' && this.fieldLabel.length) {
135                 Roo.log("left and has label");
136                 cfg.cn = [
137                     
138                     {
139                         tag: 'label',
140                         'for' :  id,
141                         cls : 'control-label col-sm-' + this.labelWidth,
142                         html : this.fieldLabel
143                         
144                     },
145                     {
146                         cls : "col-sm-" + (12 - this.labelWidth), 
147                         cn: [
148                             inputblock
149                         ]
150                     }
151                     
152                 ];
153         } else if ( this.fieldLabel.length) {
154                 Roo.log(" label");
155                  cfg.cn = [
156                    
157                     {
158                         tag: 'label',
159                         //cls : 'input-group-addon',
160                         html : this.fieldLabel
161                         
162                     },
163                     
164                     inputblock
165                     
166                 ];
167
168         } else {
169             
170                    Roo.log(" no label && no align");
171                 cfg.cn = [
172                     
173                         inputblock
174                     
175                 ];
176                 
177                 
178         }
179         
180         if (this.disabled) {
181             input.disabled=true;
182         }
183         
184         return cfg;
185         
186     },
187     /**
188      * return the real textarea element.
189      */
190     inputEl: function ()
191     {
192         return this.el.select('textarea.form-control',true).first();
193     }
194 });
195
196