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="roo-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());
164 this.dayField.render(this.el.select('.roo-date-split-field-day', true).first(), null);
166 this.monthField = new Roo.bootstrap.MonthField({
167 after : '<i class=\"fa fa-calendar\"></i>',
168 allowBlank : this.monthAllowBlank,
169 placeholder : this.monthPlaceholder,
172 render : function (_self)
174 this.el.select('span.input-group-addon', true).first().on('click', function(e){
179 select : function (_self, oldvalue, newvalue)
181 _this.setValue(_this.getValue());
186 this.monthField.render(this.el.select('.roo-date-split-field-month', true).first(), null);
188 this.yearField = new Roo.bootstrap.ComboBox({
189 allowBlank : this.yearAllowBlank,
191 displayField : 'value',
194 forceSelection : true,
196 placeholder : this.yearPlaceholder,
197 selectOnFocus : true,
198 tpl : '<div class="roo-select2-result"><b>{value}</b></div>',
199 triggerAction : 'all',
201 valueField : 'value',
202 store : new Roo.data.SimpleStore({
205 _this.fireEvent('years', _this, years);
211 select : function (_self, record, index)
213 _this.setValue(_this.getValue());
218 this.yearField.render(this.el.select('.roo-date-split-field-year', true).first(), null);
221 setValue : function(v, format)
223 this.inputEl.dom.value = v;
225 var f = format || (this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat);
227 var d = Date.parseDate(v, f);
234 this.setDay(d.format(this.dayFormat));
235 this.setMonth(d.format(this.monthFormat));
236 this.setYear(d.format(this.yearFormat));
245 this.dayField.setValue(v);
246 this.inputEl.dom.value = this.getValue();
251 setMonth : function(v)
253 this.monthField.setValue(v, true);
254 this.inputEl.dom.value = this.getValue();
259 setYear : function(v)
261 this.yearField.setValue(v);
262 this.inputEl.dom.value = this.getValue();
269 return this.dayField.getValue();
272 getMonth : function()
274 return this.monthField.getValue();
279 return this.yearField.getValue();
282 getValue : function()
284 var f = this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat;
286 var date = this.yearField.getValue() + '-' + this.monthField.getValue() + '-' + this.dayField.getValue();
296 this.inputEl.dom.value = '';
301 validate : function()
303 var d = this.dayField.validate();
304 var m = this.monthField.validate();
305 var y = this.yearField.validate();
310 (!this.dayAllowBlank && !d) ||
311 (!this.monthAllowBlank && !m) ||
312 (!this.yearAllowBlank && !y)
317 if(this.dayAllowBlank && this.monthAllowBlank && this.yearAllowBlank){
331 markValid : function()
334 var label = this.el.select('label', true).first();
335 var icon = this.el.select('i.fa-star', true).first();
341 this.fireEvent('valid', this);
345 * Mark this field as invalid
346 * @param {String} msg The validation message
348 markInvalid : function(msg)
351 var label = this.el.select('label', true).first();
352 var icon = this.el.select('i.fa-star', true).first();
355 this.el.select('.roo-date-split-field-label', true).createChild({
357 cls : 'text-danger fa fa-lg fa-star',
358 tooltip : 'This field is required',
359 style : 'margin-right:5px;'
363 this.fireEvent('invalid', this, msg);
366 clearInvalid : function()
368 var label = this.el.select('label', true).first();
369 var icon = this.el.select('i.fa-star', true).first();
375 this.fireEvent('valid', this);