10 * @class Roo.bootstrap.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.DateSplitField = function(config){
37 Roo.bootstrap.DateSplitField.superclass.constructor.call(this, config);
43 * getting the data of years
44 * @param {Roo.bootstrap.DateSplitField} this
45 * @param {Object} years
50 * getting the data of days
51 * @param {Roo.bootstrap.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.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';
112 cls : 'column roo-date-split-field-label col-md-' + ((this.labelAlign == 'top') ? '12' : this.labelWidth),
116 html : this.fieldLabel
122 Roo.each(['day', 'month', 'year'], function(t){
125 cls : 'column roo-date-split-field-' + t + ' col-md-' + ((this.labelAlign == 'top') ? '4' : ((12 - this.labelWidth) / 3))
134 return this.el.select('.roo-date-split-field-group-value', true).first();
137 onRender : function(ct, position)
141 Roo.bootstrap.NavProgressBar.superclass.onRender.call(this, ct, position);
143 this.inputEl = this.el.select('.roo-date-split-field-group-value', true).first();
145 this.dayField = new Roo.bootstrap.ComboBox({
146 allowBlank : this.dayAllowBlank,
148 displayField : 'value',
151 forceSelection : true,
153 placeholder : this.dayPlaceholder,
154 selectOnFocus : true,
155 tpl : '<div class="roo-select2-result"><b>{value}</b></div>',
156 triggerAction : 'all',
158 valueField : 'value',
159 store : new Roo.data.SimpleStore({
162 _this.fireEvent('days', _this, days);
168 select : function (_self, record, index)
170 _this.setValue(_this.getValue());
175 this.dayField.render(this.el.select('.roo-date-split-field-day', true).first(), null);
177 this.monthField = new Roo.bootstrap.MonthField({
178 after : '<i class=\"fa fa-calendar\"></i>',
179 allowBlank : this.monthAllowBlank,
180 placeholder : this.monthPlaceholder,
183 render : function (_self)
185 this.el.select('span.input-group-addon', true).first().on('click', function(e){
190 select : function (_self, oldvalue, newvalue)
192 _this.setValue(_this.getValue());
197 this.monthField.render(this.el.select('.roo-date-split-field-month', true).first(), null);
199 this.yearField = new Roo.bootstrap.ComboBox({
200 allowBlank : this.yearAllowBlank,
202 displayField : 'value',
205 forceSelection : true,
207 placeholder : this.yearPlaceholder,
208 selectOnFocus : true,
209 tpl : '<div class="roo-select2-result"><b>{value}</b></div>',
210 triggerAction : 'all',
212 valueField : 'value',
213 store : new Roo.data.SimpleStore({
216 _this.fireEvent('years', _this, years);
222 select : function (_self, record, index)
224 _this.setValue(_this.getValue());
229 this.yearField.render(this.el.select('.roo-date-split-field-year', true).first(), null);
232 setValue : function(v, format)
234 this.inputEl.dom.value = v;
236 var f = format || (this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat);
238 var d = Date.parseDate(v, f);
245 this.setDay(d.format(this.dayFormat));
246 this.setMonth(d.format(this.monthFormat));
247 this.setYear(d.format(this.yearFormat));
256 this.dayField.setValue(v);
257 this.inputEl.dom.value = this.getValue();
262 setMonth : function(v)
264 this.monthField.setValue(v, true);
265 this.inputEl.dom.value = this.getValue();
270 setYear : function(v)
272 this.yearField.setValue(v);
273 this.inputEl.dom.value = this.getValue();
280 return this.dayField.getValue();
283 getMonth : function()
285 return this.monthField.getValue();
290 return this.yearField.getValue();
293 getValue : function()
295 var f = this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat;
297 var date = this.yearField.getValue() + '-' + this.monthField.getValue() + '-' + this.dayField.getValue();
307 this.inputEl.dom.value = '';
312 validate : function()
314 var d = this.dayField.validate();
315 var m = this.monthField.validate();
316 var y = this.yearField.validate();
321 (!this.dayAllowBlank && !d) ||
322 (!this.monthAllowBlank && !m) ||
323 (!this.yearAllowBlank && !y)
328 if(this.dayAllowBlank && this.monthAllowBlank && this.yearAllowBlank){
342 markValid : function()
345 var label = this.el.select('label', true).first();
346 var icon = this.el.select('i.fa-star', true).first();
352 this.fireEvent('valid', this);
356 * Mark this field as invalid
357 * @param {String} msg The validation message
359 markInvalid : function(msg)
362 var label = this.el.select('label', true).first();
363 var icon = this.el.select('i.fa-star', true).first();
366 this.el.select('.roo-date-split-field-label', true).createChild({
368 cls : 'text-danger fa fa-lg fa-star',
369 tooltip : 'This field is required',
370 style : 'margin-right:5px;'
374 this.fireEvent('invalid', this, msg);
377 clearInvalid : function()
379 var label = this.el.select('label', true).first();
380 var icon = this.el.select('i.fa-star', true).first();
386 this.fireEvent('valid', this);