add altField option

This commit is contained in:
t1m0n 2015-12-04 12:23:05 +03:00
parent a0d00a6e20
commit 45fedcb04e
3 changed files with 35 additions and 1 deletions

17
dist/js/datepicker.js vendored
View File

@ -19,6 +19,8 @@ var Datepicker;
firstDay: '',
weekends: [6, 0],
dateFormat: '',
altField: '',
altFieldDateFormat: '@',
toggleSelected: true,
position: 'bottom left',
@ -101,6 +103,10 @@ var Datepicker;
this.elIsInput = true;
}
if (this.opts.altField) {
this.$altField = typeof this.opts.altField == 'string' ? $(this.opts.altField) : this.opts.altField;
}
this.inited = false;
this.visible = false;
this.silent = false; // Need to prevent unnecessary rendering
@ -290,6 +296,8 @@ var Datepicker;
d = Datepicker.getParsedDate(date);
switch (true) {
case /@/.test(result):
result = result.replace(/@/, date.getTime());
case /dd/.test(result):
result = result.replace(/\bdd\b/, d.fullDate);
case /d/.test(result):
@ -457,9 +465,18 @@ var Datepicker;
_setInputValue: function () {
var _this = this,
format = this.loc.dateFormat,
altFormat = this.opts.altFieldDateFormat,
value = this.selectedDates.map(function (date) {
return _this.formatDate(format, date)
}),
altValues;
if (this.$altField) {
altValues = this.selectedDates.map(function (date) {
return _this.formatDate(altFormat, date)
});
this.$altField.val(altValues);
}
value = value.join(this.opts.multipleDatesSeparator);

File diff suppressed because one or more lines are too long

View File

@ -19,6 +19,8 @@ var Datepicker;
firstDay: '',
weekends: [6, 0],
dateFormat: '',
altField: '',
altFieldDateFormat: '@',
toggleSelected: true,
position: 'bottom left',
@ -101,6 +103,10 @@ var Datepicker;
this.elIsInput = true;
}
if (this.opts.altField) {
this.$altField = typeof this.opts.altField == 'string' ? $(this.opts.altField) : this.opts.altField;
}
this.inited = false;
this.visible = false;
this.silent = false; // Need to prevent unnecessary rendering
@ -290,6 +296,8 @@ var Datepicker;
d = Datepicker.getParsedDate(date);
switch (true) {
case /@/.test(result):
result = result.replace(/@/, date.getTime());
case /dd/.test(result):
result = result.replace(/\bdd\b/, d.fullDate);
case /d/.test(result):
@ -457,9 +465,18 @@ var Datepicker;
_setInputValue: function () {
var _this = this,
format = this.loc.dateFormat,
altFormat = this.opts.altFieldDateFormat,
value = this.selectedDates.map(function (date) {
return _this.formatDate(format, date)
}),
altValues;
if (this.$altField) {
altValues = this.selectedDates.map(function (date) {
return _this.formatDate(altFormat, date)
});
this.$altField.val(altValues);
}
value = value.join(this.opts.multipleDatesSeparator);