fix #7616 - invalid field changes
[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){
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){
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'){
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                 feedback.update('');
190             }
191             
192         }
193         
194         this.fireEvent('valid', this);
195     },
196     
197      /**
198      * Mark this field as valid
199      */
200     markValid : function()
201     {
202         if(!this.el  || this.preventMark){ // not rendered
203             return;
204         }
205         
206         this.el.removeClass([this.invalidClass, this.validClass]);
207         this.inputEl().removeClass(['is-valid', 'is-invalid']);
208         
209         var feedback = this.el.select('.form-control-feedback', true).first();
210             
211         if(feedback){
212             this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
213             feedback.update('');
214         }
215
216         if(this.disabled || this.allowBlank){
217             return;
218         }
219         
220         var label = this.el.select('label', true).first();
221         var icon = this.el.select('i.fa-star', true).first();
222         
223         //if(label && icon){
224         //    icon.remove();
225         //}
226         if (Roo.bootstrap.version == 3) {
227             this.el.addClass(this.validClass);
228         } else {
229             this.inputEl().addClass('is-valid');
230         }
231         
232         
233         if(this.hasFeedback && this.inputType != 'hidden'){
234             
235             var feedback = this.el.select('.form-control-feedback', true).first();
236             
237             if(feedback){
238                 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
239                 this.el.select('.form-control-feedback', true).first().addClass([this.validFeedbackClass]);
240             }
241             
242         }
243         
244         this.fireEvent('valid', this);
245     },
246     
247      /**
248      * Mark this field as invalid
249      * @param {String} msg The validation message
250      */
251     markInvalid : function(msg)
252     {
253         if(!this.el  || this.preventMark){ // not rendered
254             return;
255         }
256         
257         this.el.removeClass([this.invalidClass, this.validClass]);
258         this.inputEl().removeClass(['is-valid', 'is-invalid']);
259         
260         var feedback = this.el.select('.form-control-feedback', true).first();
261             
262         if(feedback){
263             this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
264             feedback.update('');
265         }
266
267         if(this.disabled){
268             return;
269         }
270         
271         var label = this.el.select('label', true).first();
272         //var icon = this.el.select('i.fa-star', true).first();
273         
274         //if(!this.getValue().length && label && !icon){
275           /*  this.el.createChild({
276                 tag : 'i',
277                 cls : 'text-danger fa fa-lg fa-star',
278                 tooltip : 'This field is required',
279                 style : 'margin-right:5px;'
280             }, label, true);
281             */
282         //}
283         
284         if (Roo.bootstrap.version == 3) {
285             this.el.addClass(this.invalidClass);
286         } else {
287             this.inputEl().addClass('is-invalid');
288         }
289         
290         // fixme ... this may be depricated need to test..
291         if(this.hasFeedback && this.inputType != 'hidden'){
292             
293             var feedback = this.el.select('.form-control-feedback', true).first();
294             
295             if(feedback){
296                 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
297                 
298                 this.el.select('.form-control-feedback', true).first().addClass([this.invalidFeedbackClass]);
299
300                 feedback.update(this.invalidText);
301
302                 if(!this.allowBlank && !this.getRawValue().length){
303                     feedback.update(this.blankText);
304                 }
305                 
306             }
307             
308         }
309         
310         this.fireEvent('invalid', this, msg);
311     }
312 });
313
314