Skip to content
This repository has been archived by the owner on May 31, 2021. It is now read-only.

Fix bug about datetimepicker #186

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/js/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@
if(!calendar) {
if(!params.value && $this.val()) params.value = [$this.val()];
//默认显示今天
if(!params.value) {
if(!params.value || new Date(params.value[0]).toString() == 'Invalid Date') {
var today = new Date();
params.value = [today.getFullYear() + "-" + format(today.getMonth() + 1) + "-" + format(today.getDate())];
}
Expand Down
28 changes: 27 additions & 1 deletion src/js/datetime-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,23 @@
var min = self.arrayToDate(self.stringToArray(typeof params.min === "function" ? params.min() : params.min));

if(current < +min) {
if (!lastValidValues) {
var minDate = [min.getFullYear(), self.formatNumber(min.getMonth() + 1), self.formatNumber(min.getDate()),
self.formatNumber(min.getHours()), self.formatNumber(min.getMinutes())];
lastValidValues = minDate;
}
picker.setValue(lastValidValues);
valid = false;
}
}
if(params.max) {
var max = self.arrayToDate(self.stringToArray(typeof params.max === "function" ? params.max() : params.max));
if(current > +max) {
if (!lastValidValues) {
var maxDate = [max.getFullYear(), self.formatNumber(max.getMonth() + 1), self.formatNumber(max.getDate()),
self.formatNumber(max.getHours()), self.formatNumber(max.getMinutes())];
lastValidValues = maxDate;
}
picker.setValue(lastValidValues);
valid = false;
}
Expand Down Expand Up @@ -152,7 +162,23 @@
};

var inputValue = this.input.val();
if(inputValue) config.value = this.stringToArray(inputValue);
if (inputValue) {
config.value = this.stringToArray(inputValue);
}
else {
if (params.min) {
var min = this.arrayToDate(self.stringToArray(typeof params.min === "function" ? params.min() : params.min));
if (min >= this.arrayToDate(config.value)) {
config.value = [min.getFullYear(), this.formatNumber(min.getMonth() + 1), this.formatNumber(min.getDate()), this.formatNumber(min.getHours()), this.formatNumber(min.getMinutes())];
}
}
if (params.max) {
var max = this.arrayToDate(self.stringToArray(typeof params.max === "function" ? params.max() : params.max));
if (max <= this.arrayToDate(config.value)) {
config.value = [max.getFullYear(), this.formatNumber(max.getMonth() + 1), this.formatNumber(max.getDate()), this.formatNumber(max.getHours()), this.formatNumber(max.getMinutes())];
}
}
}

return config;
}
Expand Down