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);
143 this.dayField.render(this.el.select('.roo-date-split-field-day', true).first(), null);
145 this.monthField = new Roo.bootstrap.MonthField({
146 after : '<i class=\"fa fa-calendar\"></i>',
147 allowBlank : this.monthAllowBlank,
148 placeholder : this.monthPlaceholder,
151 render : function (_self)
153 this.el.select('span.input-group-addon', true).first().on('click', function(e){
161 this.monthField.render(this.el.select('.roo-date-split-field-month', true).first(), null);
163 this.yearField = new Roo.bootstrap.ComboBox({
164 allowBlank : this.yearAllowBlank,
166 displayField : 'value',
169 forceSelection : true,
171 placeholder : this.yearPlaceholder,
172 selectOnFocus : true,
173 tpl : '<div class="select2-result"><b>{value}</b></div>',
174 triggerAction : 'all',
176 valueField : 'value',
177 store : new Roo.data.SimpleStore({
180 _this.fireEvent('years', _this, years);
187 this.yearField.render(this.el.select('.roo-date-split-field-year', true).first(), null);
190 setValue : function(v, format)
192 var f = format || (this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat);
194 var d = Date.parseDate(v, f);
196 this.dayField.setValue(d.format(this.dayFormat));
197 this.monthField.setValue(d.format(this.monthFormat));
198 this.yearField.setValue(d.format(this.yearFormat));
203 getValue : function()
205 var f = this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat;
207 var date = this.yearField.getValue() + '-' + this.monthField.getValue() + '-' + this.dayField.getValue();
212 validate : function()
214 var d = this.dayField.validate();
215 var m = this.monthField.validate();
216 var y = this.yearField.validate();
221 (!this.dayAllowBlank && !d) ||
222 (!this.monthAllowBlank && !m) ||
223 (!this.yearAllowBlank && !y)
233 markValid : function()
236 var label = this.el.select('label', true).first();
237 var icon = this.el.select('i.fa-star', true).first();
243 this.fireEvent('valid', this);
247 * Mark this field as invalid
248 * @param {String} msg The validation message
250 markInvalid : function(msg)
253 var label = formGroup.select('label', true).first();
254 var icon = formGroup.select('i.fa-star', true).first();
257 this.el.findParent('.form-group', false, true).createChild({
259 cls : 'text-danger fa fa-lg fa-star',
260 tooltip : 'This field is required',
261 style : 'margin-right:5px;'
265 this.fireEvent('invalid', this, msg);