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.hasFeedback){
125                 inputblock.cls += ' has-feedback';
126                 inputblock.cn.push(feedback);
127             }
128             
129             if (this.after) {
130                 inputblock.cn.push({
131                     tag :'span',
132                     cls : 'input-group-addon',
133                     html : this.after
134                 });
135             }
136             
137         }
138         
139         if (align ==='left' && this.fieldLabel.length) {
140                 Roo.log("left and has label");
141                 cfg.cn = [
142                     
143                     {
144                         tag: 'label',
145                         'for' :  id,
146                         cls : 'control-label col-sm-' + this.labelWidth,
147                         html : this.fieldLabel
148                         
149                     },
150                     {
151                         cls : "col-sm-" + (12 - this.labelWidth), 
152                         cn: [
153                             inputblock
154                         ]
155                     }
156                     
157                 ];
158         } else if ( this.fieldLabel.length) {
159                 Roo.log(" label");
160                  cfg.cn = [
161                    
162                     {
163                         tag: 'label',
164                         //cls : 'input-group-addon',
165                         html : this.fieldLabel
166                         
167                     },
168                     
169                     inputblock
170                     
171                 ];
172
173         } else {
174             
175                    Roo.log(" no label && no align");
176                 cfg.cn = [
177                     
178                         inputblock
179                     
180                 ];
181                 
182                 
183         }
184         
185         if (this.disabled) {
186             input.disabled=true;
187         }
188         
189         return cfg;
190         
191     },
192     /**
193      * return the real textarea element.
194      */
195     inputEl: function ()
196     {
197         return this.el.select('textarea.form-control',true).first();
198     }
199 });
200
201