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'
28 * Create a new DateSplitField
29 * @param {Object} config The config object
32 Roo.bootstrap.DateSplitField = function(config){
33 Roo.bootstrap.DateSplitField.superclass.constructor.call(this, config);
39 * getting the data of years
40 * @param {Roo.bootstrap.DateSplitField} this
41 * @param {Object} years
46 * getting the data of days
47 * @param {Roo.bootstrap.DateSplitField} this
48 * @param {Object} days
53 * Fires after the field has been marked as invalid.
54 * @param {Roo.form.Field} this
55 * @param {String} msg The validation message
60 * Fires after the field has been validated with no errors.
61 * @param {Roo.form.Field} this
67 Roo.extend(Roo.bootstrap.DateSplitField, Roo.bootstrap.Component, {
72 dayAllowBlank : false,
73 monthAllowBlank : false,
74 yearAllowBlank : false,
76 monthPlaceholder : '',
83 getAutoCreate : function()
87 cls : 'row roo-date-split-field-group',
92 cls : 'form-hidden-field roo-date-split-field-group-value',
101 cls : 'column roo-date-split-field-label col-md-' + ((this.labelAlign == 'top') ? '12' : this.labelWidth),
105 html : this.fieldLabel
111 Roo.each(['day', 'month', 'year'], function(t){
114 cls : 'column roo-date-split-field-' + t + ' col-md-' + ((this.labelAlign == 'top') ? '4' : ((12 - this.labelWidth) / 3))
123 return this.el.select('.roo-date-split-field-group-value', true).first();
126 onRender : function(ct, position)
130 Roo.bootstrap.NavProgressBar.superclass.onRender.call(this, ct, position);
132 this.inputEl = this.el.select('.roo-date-split-field-group-value', true).first();
134 this.dayField = new Roo.bootstrap.ComboBox({
135 allowBlank : this.dayAllowBlank,
137 displayField : 'value',
140 forceSelection : true,
142 placeholder : this.dayPlaceholder,
143 selectOnFocus : true,
144 tpl : '<div class="select2-result"><b>{value}</b></div>',
145 triggerAction : 'all',
147 valueField : 'value',
148 store : new Roo.data.SimpleStore({
151 _this.fireEvent('days', _this, days);
157 select : function (_self, record, index)
159 _this.setValue(_this.getValue());
165 this.dayField.render(this.el.select('.roo-date-split-field-day', true).first(), null);
167 this.monthField = new Roo.bootstrap.MonthField({
168 after : '<i class=\"fa fa-calendar\"></i>',
169 allowBlank : this.monthAllowBlank,
170 placeholder : this.monthPlaceholder,
173 render : function (_self)
175 this.el.select('span.input-group-addon', true).first().on('click', function(e){
180 select : function (_self, oldvalue, newvalue)
182 _this.setValue(_this.getValue());
188 this.monthField.render(this.el.select('.roo-date-split-field-month', true).first(), null);
190 this.yearField = new Roo.bootstrap.ComboBox({
191 allowBlank : this.yearAllowBlank,
193 displayField : 'value',
196 forceSelection : true,
198 placeholder : this.yearPlaceholder,
199 selectOnFocus : true,
200 tpl : '<div class="select2-result"><b>{value}</b></div>',
201 triggerAction : 'all',
203 valueField : 'value',
204 store : new Roo.data.SimpleStore({
207 _this.fireEvent('years', _this, years);
213 select : function (_self, record, index)
215 _this.setValue(_this.getValue());
221 this.yearField.render(this.el.select('.roo-date-split-field-year', true).first(), null);
224 setValue : function(v, format)
226 this.inputEl.dom.value = v;
228 var f = format || (this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat);
230 var d = Date.parseDate(v, f);
236 this.setDay(d.format(this.dayFormat));
237 this.setMonth(d.format(this.monthFormat));
238 this.setYear(d.format(this.yearFormat));
247 this.dayField.setValue(v);
251 setMonth : function(v)
253 this.monthField.setValue(v);
257 setYear : function(v)
259 this.yearField.setValue(v);
263 getValue : function()
265 var f = this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat;
267 var date = this.yearField.getValue() + '-' + this.monthField.getValue() + '-' + this.dayField.getValue();
272 validate : function()
274 var d = this.dayField.validate();
275 var m = this.monthField.validate();
276 var y = this.yearField.validate();
281 (!this.dayAllowBlank && !d) ||
282 (!this.monthAllowBlank && !m) ||
283 (!this.yearAllowBlank && !y)
288 if(this.dayAllowBlank && this.monthAllowBlank && this.yearAllowBlank){
302 markValid : function()
305 var label = this.el.select('label', true).first();
306 var icon = this.el.select('i.fa-star', true).first();
312 this.fireEvent('valid', this);
316 * Mark this field as invalid
317 * @param {String} msg The validation message
319 markInvalid : function(msg)
322 var label = this.el.select('label', true).first();
323 var icon = this.el.select('i.fa-star', true).first();
326 this.el.select('.roo-date-split-field-label', true).createChild({
328 cls : 'text-danger fa fa-lg fa-star',
329 tooltip : 'This field is required',
330 style : 'margin-right:5px;'
334 this.fireEvent('invalid', this, msg);
337 clearInvalid : function()
339 var label = this.el.select('label', true).first();
340 var icon = this.el.select('i.fa-star', true).first();
346 this.fireEvent('valid', this);