10 * @class Roo.bootstrap.form.DateSplitField
11 * @extends Roo.bootstrap.Component
12 * Bootstrap DateSplitField class
13 * @cfg {string} fieldLabel - the label associated
14 * @cfg {Number} labelWidth set the width of label (0-12)
15 * @cfg {String} labelAlign (top|left)
16 * @cfg {Boolean} dayAllowBlank (true|false) default false
17 * @cfg {Boolean} monthAllowBlank (true|false) default false
18 * @cfg {Boolean} yearAllowBlank (true|false) default false
19 * @cfg {string} dayPlaceholder
20 * @cfg {string} monthPlaceholder
21 * @cfg {string} yearPlaceholder
22 * @cfg {string} dayFormat default 'd'
23 * @cfg {string} monthFormat default 'm'
24 * @cfg {string} yearFormat default 'Y'
25 * @cfg {Number} labellg set the width of label (1-12)
26 * @cfg {Number} labelmd set the width of label (1-12)
27 * @cfg {Number} labelsm set the width of label (1-12)
28 * @cfg {Number} labelxs set the width of label (1-12)
32 * Create a new DateSplitField
33 * @param {Object} config The config object
36 Roo.bootstrap.form.DateSplitField = function(config){
37 Roo.bootstrap.form.DateSplitField.superclass.constructor.call(this, config);
43 * getting the data of years
44 * @param {Roo.bootstrap.form.DateSplitField} this
45 * @param {Object} years
50 * getting the data of days
51 * @param {Roo.bootstrap.form.DateSplitField} this
52 * @param {Object} days
57 * Fires after the field has been marked as invalid.
58 * @param {Roo.form.Field} this
59 * @param {String} msg The validation message
64 * Fires after the field has been validated with no errors.
65 * @param {Roo.form.Field} this
71 Roo.extend(Roo.bootstrap.form.DateSplitField, Roo.bootstrap.Component, {
76 dayAllowBlank : false,
77 monthAllowBlank : false,
78 yearAllowBlank : false,
80 monthPlaceholder : '',
91 getAutoCreate : function()
95 cls : 'row roo-date-split-field-group',
100 cls : 'form-hidden-field roo-date-split-field-group-value',
106 var labelCls = 'col-md-12';
107 var contentCls = 'col-md-4';
113 cls : 'column roo-date-split-field-label col-md-' + ((this.labelAlign == 'top') ? '12' : this.labelWidth),
117 html : this.fieldLabel
122 if(this.labelAlign == 'left'){
124 if(this.labelWidth > 12){
125 label.style = "width: " + this.labelWidth + 'px';
128 if(this.labelWidth < 13 && this.labelmd == 0){
129 this.labelmd = this.labelWidth;
132 if(this.labellg > 0){
133 labelCls = ' col-lg-' + this.labellg;
134 contentCls = ' col-lg-' + ((12 - this.labellg) / 3);
137 if(this.labelmd > 0){
138 labelCls = ' col-md-' + this.labelmd;
139 contentCls = ' col-md-' + ((12 - this.labelmd) / 3);
142 if(this.labelsm > 0){
143 labelCls = ' col-sm-' + this.labelsm;
144 contentCls = ' col-sm-' + ((12 - this.labelsm) / 3);
147 if(this.labelxs > 0){
148 labelCls = ' col-xs-' + this.labelxs;
149 contentCls = ' col-xs-' + ((12 - this.labelxs) / 3);
153 label.cls += ' ' + labelCls;
158 Roo.each(['day', 'month', 'year'], function(t){
161 cls : 'column roo-date-split-field-' + t + ' ' + contentCls
170 return this.el.select('.roo-date-split-field-group-value', true).first();
173 onRender : function(ct, position)
177 Roo.bootstrap.DateSplitFiel.superclass.onRender.call(this, ct, position);
179 this.inputEl = this.el.select('.roo-date-split-field-group-value', true).first();
181 this.dayField = new Roo.bootstrap.form.ComboBox({
182 allowBlank : this.dayAllowBlank,
184 displayField : 'value',
187 forceSelection : true,
189 placeholder : this.dayPlaceholder,
190 selectOnFocus : true,
191 tpl : '<div class="roo-select2-result"><b>{value}</b></div>',
192 triggerAction : 'all',
194 valueField : 'value',
195 store : new Roo.data.SimpleStore({
198 _this.fireEvent('days', _this, days);
204 select : function (_self, record, index)
206 _this.setValue(_this.getValue());
211 this.dayField.render(this.el.select('.roo-date-split-field-day', true).first(), null);
213 this.monthField = new Roo.bootstrap.form.MonthField({
214 after : '<i class=\"fa fa-calendar\"></i>',
215 allowBlank : this.monthAllowBlank,
216 placeholder : this.monthPlaceholder,
219 render : function (_self)
221 this.el.select('span.input-group-addon', true).first().on('click', function(e){
226 select : function (_self, oldvalue, newvalue)
228 _this.setValue(_this.getValue());
233 this.monthField.render(this.el.select('.roo-date-split-field-month', true).first(), null);
235 this.yearField = new Roo.bootstrap.form.ComboBox({
236 allowBlank : this.yearAllowBlank,
238 displayField : 'value',
241 forceSelection : true,
243 placeholder : this.yearPlaceholder,
244 selectOnFocus : true,
245 tpl : '<div class="roo-select2-result"><b>{value}</b></div>',
246 triggerAction : 'all',
248 valueField : 'value',
249 store : new Roo.data.SimpleStore({
252 _this.fireEvent('years', _this, years);
258 select : function (_self, record, index)
260 _this.setValue(_this.getValue());
265 this.yearField.render(this.el.select('.roo-date-split-field-year', true).first(), null);
268 setValue : function(v, format)
270 this.inputEl.dom.value = v;
272 var f = format || (this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat);
274 var d = Date.parseDate(v, f);
281 this.setDay(d.format(this.dayFormat));
282 this.setMonth(d.format(this.monthFormat));
283 this.setYear(d.format(this.yearFormat));
292 this.dayField.setValue(v);
293 this.inputEl.dom.value = this.getValue();
298 setMonth : function(v)
300 this.monthField.setValue(v, true);
301 this.inputEl.dom.value = this.getValue();
306 setYear : function(v)
308 this.yearField.setValue(v);
309 this.inputEl.dom.value = this.getValue();
316 return this.dayField.getValue();
319 getMonth : function()
321 return this.monthField.getValue();
326 return this.yearField.getValue();
329 getValue : function()
331 var f = this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat;
333 var date = this.yearField.getValue() + '-' + this.monthField.getValue() + '-' + this.dayField.getValue();
343 this.inputEl.dom.value = '';
348 validate : function()
350 var d = this.dayField.validate();
351 var m = this.monthField.validate();
352 var y = this.yearField.validate();
357 (!this.dayAllowBlank && !d) ||
358 (!this.monthAllowBlank && !m) ||
359 (!this.yearAllowBlank && !y)
364 if(this.dayAllowBlank && this.monthAllowBlank && this.yearAllowBlank){
378 markValid : function()
381 var label = this.el.select('label', true).first();
382 var icon = this.el.select('i.fa-star', true).first();
388 this.fireEvent('valid', this);
392 * Mark this field as invalid
393 * @param {String} msg The validation message
395 markInvalid : function(msg)
398 var label = this.el.select('label', true).first();
399 var icon = this.el.select('i.fa-star', true).first();
402 this.el.select('.roo-date-split-field-label', true).createChild({
404 cls : 'text-danger fa fa-lg fa-star',
405 tooltip : 'This field is required',
406 style : 'margin-right:5px;'
410 this.fireEvent('invalid', this, msg);
413 clearInvalid : function()
415 var label = this.el.select('label', true).first();
416 var icon = this.el.select('i.fa-star', true).first();
422 this.fireEvent('valid', this);