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 : '',
82 getAutoCreate : function()
86 cls : 'row roo-date-split-field-group',
93 cls : 'column roo-date-split-field-label col-md-' + ((this.labelAlign == 'top') ? '12' : this.labelWidth),
97 html : this.fieldLabel
103 Roo.each(['day', 'month', 'year'], function(t){
106 cls : 'column roo-date-split-field-' + t + ' col-md-' + ((this.labelAlign == 'top') ? '4' : ((12 - this.labelWidth) / 3))
113 onRender : function(ct, position)
117 Roo.bootstrap.NavProgressBar.superclass.onRender.call(this, ct, position);
119 this.dayField = new Roo.bootstrap.ComboBox({
120 allowBlank : this.dayAllowBlank,
122 displayField : 'value',
125 forceSelection : true,
127 placeholder : this.dayPlaceholder,
128 selectOnFocus : true,
129 tpl : '<div class="select2-result"><b>{value}</b></div>',
130 triggerAction : 'all',
132 valueField : 'value',
133 store : new Roo.data.SimpleStore({
136 _this.fireEvent('days', _this, days);
142 select : function (_self, record, index)
149 this.dayField.render(this.el.select('.roo-date-split-field-day', true).first(), null);
151 this.monthField = new Roo.bootstrap.MonthField({
152 after : '<i class=\"fa fa-calendar\"></i>',
153 allowBlank : this.monthAllowBlank,
154 placeholder : this.monthPlaceholder,
157 render : function (_self)
159 this.el.select('span.input-group-addon', true).first().on('click', function(e){
164 select : function (_self, oldvalue, newvalue)
171 this.monthField.render(this.el.select('.roo-date-split-field-month', true).first(), null);
173 this.yearField = new Roo.bootstrap.ComboBox({
174 allowBlank : this.yearAllowBlank,
176 displayField : 'value',
179 forceSelection : true,
181 placeholder : this.yearPlaceholder,
182 selectOnFocus : true,
183 tpl : '<div class="select2-result"><b>{value}</b></div>',
184 triggerAction : 'all',
186 valueField : 'value',
187 store : new Roo.data.SimpleStore({
190 _this.fireEvent('years', _this, years);
196 select : function (_self, record, index)
203 this.yearField.render(this.el.select('.roo-date-split-field-year', true).first(), null);
206 setValue : function(v, format)
208 var f = format || (this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat);
210 var d = Date.parseDate(v, f);
212 this.dayField.setValue(d.format(this.dayFormat));
213 this.monthField.setValue(d.format(this.monthFormat));
214 this.yearField.setValue(d.format(this.yearFormat));
221 this.dayField.setValue(v);
226 setMonth : function(v)
228 this.monthField.setValue(v);
233 setMonth : function(v)
235 this.monthField.setValue(v);
240 getValue : function()
242 var f = this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat;
244 var date = this.yearField.getValue() + '-' + this.monthField.getValue() + '-' + this.dayField.getValue();
249 validate : function()
251 var d = this.dayField.validate();
252 var m = this.monthField.validate();
253 var y = this.yearField.validate();
258 (!this.dayAllowBlank && !d) ||
259 (!this.monthAllowBlank && !m) ||
260 (!this.yearAllowBlank && !y)
265 if(this.dayAllowBlank && this.monthAllowBlank && this.yearAllowBlank){
279 markValid : function()
282 var label = this.el.select('label', true).first();
283 var icon = this.el.select('i.fa-star', true).first();
289 this.fireEvent('valid', this);
293 * Mark this field as invalid
294 * @param {String} msg The validation message
296 markInvalid : function(msg)
299 var label = this.el.select('label', true).first();
300 var icon = this.el.select('i.fa-star', true).first();
303 this.el.select('.roo-date-split-field-label', true).createChild({
305 cls : 'text-danger fa fa-lg fa-star',
306 tooltip : 'This field is required',
307 style : 'margin-right:5px;'
311 this.fireEvent('invalid', this, msg);