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';
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 labelCfg.style = "width: " + this.labelWidth + 'px';
128 if(this.labelWidth < 13 && this.labelmd == 0){
129 this.labelmd = this.labelWidth;
132 if(this.labellg > 0){
133 labelCfg.cls += ' col-lg-' + this.labellg;
134 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
137 if(this.labelmd > 0){
138 labelCfg.cls += ' col-md-' + this.labelmd;
139 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
142 if(this.labelsm > 0){
143 labelCfg.cls += ' col-sm-' + this.labelsm;
144 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
147 if(this.labelxs > 0){
148 labelCfg.cls += ' col-xs-' + this.labelxs;
149 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
156 Roo.each(['day', 'month', 'year'], function(t){
159 cls : 'column roo-date-split-field-' + t + ' col-md-' + ((this.labelAlign == 'top') ? '4' : ((12 - this.labelWidth) / 3))
168 return this.el.select('.roo-date-split-field-group-value', true).first();
171 onRender : function(ct, position)
175 Roo.bootstrap.NavProgressBar.superclass.onRender.call(this, ct, position);
177 this.inputEl = this.el.select('.roo-date-split-field-group-value', true).first();
179 this.dayField = new Roo.bootstrap.ComboBox({
180 allowBlank : this.dayAllowBlank,
182 displayField : 'value',
185 forceSelection : true,
187 placeholder : this.dayPlaceholder,
188 selectOnFocus : true,
189 tpl : '<div class="roo-select2-result"><b>{value}</b></div>',
190 triggerAction : 'all',
192 valueField : 'value',
193 store : new Roo.data.SimpleStore({
196 _this.fireEvent('days', _this, days);
202 select : function (_self, record, index)
204 _this.setValue(_this.getValue());
209 this.dayField.render(this.el.select('.roo-date-split-field-day', true).first(), null);
211 this.monthField = new Roo.bootstrap.MonthField({
212 after : '<i class=\"fa fa-calendar\"></i>',
213 allowBlank : this.monthAllowBlank,
214 placeholder : this.monthPlaceholder,
217 render : function (_self)
219 this.el.select('span.input-group-addon', true).first().on('click', function(e){
224 select : function (_self, oldvalue, newvalue)
226 _this.setValue(_this.getValue());
231 this.monthField.render(this.el.select('.roo-date-split-field-month', true).first(), null);
233 this.yearField = new Roo.bootstrap.ComboBox({
234 allowBlank : this.yearAllowBlank,
236 displayField : 'value',
239 forceSelection : true,
241 placeholder : this.yearPlaceholder,
242 selectOnFocus : true,
243 tpl : '<div class="roo-select2-result"><b>{value}</b></div>',
244 triggerAction : 'all',
246 valueField : 'value',
247 store : new Roo.data.SimpleStore({
250 _this.fireEvent('years', _this, years);
256 select : function (_self, record, index)
258 _this.setValue(_this.getValue());
263 this.yearField.render(this.el.select('.roo-date-split-field-year', true).first(), null);
266 setValue : function(v, format)
268 this.inputEl.dom.value = v;
270 var f = format || (this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat);
272 var d = Date.parseDate(v, f);
279 this.setDay(d.format(this.dayFormat));
280 this.setMonth(d.format(this.monthFormat));
281 this.setYear(d.format(this.yearFormat));
290 this.dayField.setValue(v);
291 this.inputEl.dom.value = this.getValue();
296 setMonth : function(v)
298 this.monthField.setValue(v, true);
299 this.inputEl.dom.value = this.getValue();
304 setYear : function(v)
306 this.yearField.setValue(v);
307 this.inputEl.dom.value = this.getValue();
314 return this.dayField.getValue();
317 getMonth : function()
319 return this.monthField.getValue();
324 return this.yearField.getValue();
327 getValue : function()
329 var f = this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat;
331 var date = this.yearField.getValue() + '-' + this.monthField.getValue() + '-' + this.dayField.getValue();
341 this.inputEl.dom.value = '';
346 validate : function()
348 var d = this.dayField.validate();
349 var m = this.monthField.validate();
350 var y = this.yearField.validate();
355 (!this.dayAllowBlank && !d) ||
356 (!this.monthAllowBlank && !m) ||
357 (!this.yearAllowBlank && !y)
362 if(this.dayAllowBlank && this.monthAllowBlank && this.yearAllowBlank){
376 markValid : 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);
390 * Mark this field as invalid
391 * @param {String} msg The validation message
393 markInvalid : function(msg)
396 var label = this.el.select('label', true).first();
397 var icon = this.el.select('i.fa-star', true).first();
400 this.el.select('.roo-date-split-field-label', true).createChild({
402 cls : 'text-danger fa fa-lg fa-star',
403 tooltip : 'This field is required',
404 style : 'margin-right:5px;'
408 this.fireEvent('invalid', this, msg);
411 clearInvalid : function()
413 var label = this.el.select('label', true).first();
414 var icon = this.el.select('i.fa-star', true).first();
420 this.fireEvent('valid', this);