2c35437f1b78955bdcb6ac96fe0ceec52fb7ac11
[roojs1] / Roo / bootstrap / form / TextArea.js
1 /*
2  * - LGPL
3  *
4  * Input
5  * 
6  */
7
8 /**
9  * @class Roo.bootstrap.form.TextArea
10  * @extends Roo.bootstrap.form.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.form.TextArea = function(config){
24     Roo.bootstrap.form.TextArea.superclass.constructor.call(this, config);
25    
26 };
27
28 Roo.extend(Roo.bootstrap.form.TextArea, Roo.bootstrap.form.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         if(this.inputType != 'hidden'){
47             cfg.cls = 'form-group' //input-group
48         }
49         
50         var input =  {
51             tag: 'textarea',
52             id : id,
53             warp : this.warp,
54             rows : this.rows,
55             value : this.value || '',
56             html: this.html || '',
57             cls : 'form-control',
58             placeholder : this.placeholder || '' 
59             
60         };
61         
62         if(this.maxLength && this.maxLength != Number.MAX_VALUE){
63             input.maxLength = this.maxLength;
64         }
65         
66         if(this.resize){
67             input.style = (typeof(input.style) == 'undefined') ? 'resize:' + this.resize : input.style + 'resize:' + this.resize;
68         }
69         
70         if(this.cols){
71             input.cols = this.cols;
72         }
73         
74         if (this.readOnly) {
75             input.readonly = true;
76         }
77         
78         if (this.name) {
79             input.name = this.name;
80         }
81         
82         if (this.size) {
83             input.cls = (typeof(input.cls) == 'undefined') ? 'input-' + this.size : input.cls + ' input-' + this.size;
84         }
85         
86         var settings=this;
87         ['xs','sm','md','lg'].map(function(size){
88             if (settings[size]) {
89                 cfg.cls += ' col-' + size + '-' + settings[size];
90             }
91         });
92         
93         var inputblock = input;
94         
95         if(this.hasFeedback && !this.allowBlank){
96             
97             var feedback = {
98                 tag: 'span',
99                 cls: 'glyphicon form-control-feedback'
100             };
101
102             inputblock = {
103                 cls : 'has-feedback',
104                 cn :  [
105                     input,
106                     feedback
107                 ] 
108             };  
109         }
110         
111         
112         if (this.before || this.after) {
113             
114             inputblock = {
115                 cls : 'input-group',
116                 cn :  [] 
117             };
118             if (this.before) {
119                 inputblock.cn.push({
120                     tag :'span',
121                     cls : 'input-group-addon',
122                     html : this.before
123                 });
124             }
125             
126             inputblock.cn.push(input);
127             
128             if(this.hasFeedback && !this.allowBlank){
129                 inputblock.cls += ' has-feedback';
130                 inputblock.cn.push(feedback);
131             }
132             
133             if (this.after) {
134                 inputblock.cn.push({
135                     tag :'span',
136                     cls : 'input-group-addon',
137                     html : this.after
138                 });
139             }
140             
141         }
142         
143         
144         cfg = this.getAutoCreateLabel( cfg, inputblock );
145
146          
147         
148         if (this.disabled) {
149             input.disabled=true;
150         }
151         
152         return cfg;
153         
154     },
155     /**
156      * return the real textarea element.
157      */
158     inputEl: function ()
159     {
160         return this.el.select('textarea.form-control',true).first();
161     },
162     
163     /**
164      * Clear any invalid styles/messages for this field
165      */
166     clearInvalid : function()
167     {
168         
169         if(!this.el || this.preventMark){ // not rendered
170             return;
171         }
172         
173         var label = this.el.select('label', true).first();
174         //var icon = this.el.select('i.fa-star', true).first();
175         
176         //if(label && icon){
177         //    icon.remove();
178         //}
179         this.el.removeClass( this.validClass);
180         this.inputEl().removeClass('is-invalid');
181          
182         if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
183             
184             var feedback = this.el.select('.form-control-feedback', true).first();
185             
186             if(feedback){
187                 this.el.select('.form-control-feedback', true).first().removeClass(this.invalidFeedbackClass);
188             }
189             
190         }
191         
192         this.fireEvent('valid', this);
193     },
194     
195      /**
196      * Mark this field as valid
197      */
198     markValid : function()
199     {
200         if(!this.el  || this.preventMark){ // not rendered
201             return;
202         }
203         
204         this.el.removeClass([this.invalidClass, this.validClass]);
205         this.inputEl().removeClass(['is-valid', 'is-invalid']);
206         
207         var feedback = this.el.select('.form-control-feedback', true).first();
208             
209         if(feedback){
210             this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
211         }
212
213         if(this.disabled || this.allowBlank){
214             return;
215         }
216         
217         var label = this.el.select('label', true).first();
218         var icon = this.el.select('i.fa-star', true).first();
219         
220         //if(label && icon){
221         //    icon.remove();
222         //}
223         if (Roo.bootstrap.version == 3) {
224             this.el.addClass(this.validClass);
225         } else {
226             this.inputEl().addClass('is-valid');
227         }
228         
229         
230         if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank && (this.getValue().length || this.forceFeedback)){
231             
232             var feedback = this.el.select('.form-control-feedback', true).first();
233             
234             if(feedback){
235                 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
236                 this.el.select('.form-control-feedback', true).first().addClass([this.validFeedbackClass]);
237             }
238             
239         }
240         
241         this.fireEvent('valid', this);
242     },
243     
244      /**
245      * Mark this field as invalid
246      * @param {String} msg The validation message
247      */
248     markInvalid : function(msg)
249     {
250         if(!this.el  || this.preventMark){ // not rendered
251             return;
252         }
253         
254         this.el.removeClass([this.invalidClass, this.validClass]);
255         this.inputEl().removeClass(['is-valid', 'is-invalid']);
256         
257         var feedback = this.el.select('.form-control-feedback', true).first();
258             
259         if(feedback){
260             this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
261         }
262
263         if(this.disabled || this.allowBlank){
264             return;
265         }
266         
267         var label = this.el.select('label', true).first();
268         //var icon = this.el.select('i.fa-star', true).first();
269         
270         //if(!this.getValue().length && label && !icon){
271           /*  this.el.createChild({
272                 tag : 'i',
273                 cls : 'text-danger fa fa-lg fa-star',
274                 tooltip : 'This field is required',
275                 style : 'margin-right:5px;'
276             }, label, true);
277             */
278         //}
279         
280         if (Roo.bootstrap.version == 3) {
281             this.el.addClass(this.invalidClass);
282         } else {
283             this.inputEl().addClass('is-invalid');
284         }
285         
286         // fixme ... this may be depricated need to test..
287         if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
288             
289             var feedback = this.el.select('.form-control-feedback', true).first();
290             
291             if(feedback){
292                 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
293                 
294                 if(this.getValue().length || this.forceFeedback){
295                     this.el.select('.form-control-feedback', true).first().addClass([this.invalidFeedbackClass]);
296                 }
297                 
298             }
299             
300         }
301         
302         this.fireEvent('invalid', this, msg);
303     }
304 });
305
306