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'
100 cls : 'column roo-date-split-field-label col-md-' + ((this.labelAlign == 'top') ? '12' : this.labelWidth),
104 html : this.fieldLabel
110 Roo.each(['day', 'month', 'year'], function(t){
113 cls : 'column roo-date-split-field-' + t + ' col-md-' + ((this.labelAlign == 'top') ? '4' : ((12 - this.labelWidth) / 3))
122 return this.el.select('.roo-date-split-field-group-value', true).first();
125 onRender : function(ct, position)
129 Roo.bootstrap.NavProgressBar.superclass.onRender.call(this, ct, position);
131 this.inputEl = this.el.select('.roo-date-split-field-group-value', true).first();
133 this.dayField = new Roo.bootstrap.ComboBox({
134 allowBlank : this.dayAllowBlank,
136 displayField : 'value',
139 forceSelection : true,
141 placeholder : this.dayPlaceholder,
142 selectOnFocus : true,
143 tpl : '<div class="select2-result"><b>{value}</b></div>',
144 triggerAction : 'all',
146 valueField : 'value',
147 store : new Roo.data.SimpleStore({
150 _this.fireEvent('days', _this, days);
156 select : function (_self, record, index)
163 this.dayField.render(this.el.select('.roo-date-split-field-day', true).first(), null);
165 this.monthField = new Roo.bootstrap.MonthField({
166 after : '<i class=\"fa fa-calendar\"></i>',
167 allowBlank : this.monthAllowBlank,
168 placeholder : this.monthPlaceholder,
171 render : function (_self)
173 this.el.select('span.input-group-addon', true).first().on('click', function(e){
178 select : function (_self, oldvalue, newvalue)
185 this.monthField.render(this.el.select('.roo-date-split-field-month', true).first(), null);
187 this.yearField = new Roo.bootstrap.ComboBox({
188 allowBlank : this.yearAllowBlank,
190 displayField : 'value',
193 forceSelection : true,
195 placeholder : this.yearPlaceholder,
196 selectOnFocus : true,
197 tpl : '<div class="select2-result"><b>{value}</b></div>',
198 triggerAction : 'all',
200 valueField : 'value',
201 store : new Roo.data.SimpleStore({
204 _this.fireEvent('years', _this, years);
210 select : function (_self, record, index)
217 this.yearField.render(this.el.select('.roo-date-split-field-year', true).first(), null);
220 setValue : function(v, format)
222 var f = format || (this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat);
224 var d = Date.parseDate(v, f);
226 this.dayField.setValue(d.format(this.dayFormat));
227 this.monthField.setValue(d.format(this.monthFormat));
228 this.yearField.setValue(d.format(this.yearFormat));
230 this.inputEl().setValue(d.format(f));
239 this.dayField.setValue(v);
245 setMonth : function(v)
247 this.monthField.setValue(v);
252 setYear : function(v)
254 this.yearField.setValue(v);
259 getValue : function()
261 var f = this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat;
263 var date = this.yearField.getValue() + '-' + this.monthField.getValue() + '-' + this.dayField.getValue();
268 validate : function()
270 var d = this.dayField.validate();
271 var m = this.monthField.validate();
272 var y = this.yearField.validate();
274 this.setValue(this.getValue());
279 (!this.dayAllowBlank && !d) ||
280 (!this.monthAllowBlank && !m) ||
281 (!this.yearAllowBlank && !y)
286 if(this.dayAllowBlank && this.monthAllowBlank && this.yearAllowBlank){
300 markValid : function()
303 var label = this.el.select('label', true).first();
304 var icon = this.el.select('i.fa-star', true).first();
310 this.fireEvent('valid', this);
314 * Mark this field as invalid
315 * @param {String} msg The validation message
317 markInvalid : function(msg)
320 var label = this.el.select('label', true).first();
321 var icon = this.el.select('i.fa-star', true).first();
324 this.el.select('.roo-date-split-field-label', true).createChild({
326 cls : 'text-danger fa fa-lg fa-star',
327 tooltip : 'This field is required',
328 style : 'margin-right:5px;'
332 this.fireEvent('invalid', this, msg);
335 clearInvalid : function()
337 var label = this.el.select('label', true).first();
338 var icon = this.el.select('i.fa-star', true).first();
344 this.fireEvent('valid', this);