Skip to content

Commit

Permalink
Merge pull request ElemeFE#184 from QingWei-Li/fix/date-picker
Browse files Browse the repository at this point in the history
DatePicker: fix set initial value
  • Loading branch information
csvwolf authored Sep 29, 2016
2 parents 1cae9b3 + 7de5306 commit 2cf9663
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/date-picker/src/basic/date-table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
</table>
</template>

<script type="text/ecmascript-6">
<script>
import { $t, getFirstDayOfMonth, getDayCountOfMonth, getWeekNumber, getStartDateOfMonth, DAY_DURATION } from '../util';
import { hasClass } from 'wind-dom/src/class';
import Vue from 'vue';
Expand Down
6 changes: 3 additions & 3 deletions packages/date-picker/src/panel/date-range.vue
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
</template>

<script type="text/ecmascript-6">
import { nextMonth, prevMonth, $t, formatDate, parseDate } from '../util';
import { nextMonth, prevMonth, toDate, $t, formatDate, parseDate } from '../util';
export default {
computed: {
Expand Down Expand Up @@ -292,8 +292,8 @@
this.minDate = null;
this.maxDate = null;
} else if (Array.isArray(newVal)) {
this.minDate = newVal[0];
this.maxDate = newVal[1];
this.minDate = toDate(newVal[0]);
this.maxDate = toDate(newVal[1]);
}
}
},
Expand Down
11 changes: 3 additions & 8 deletions packages/date-picker/src/picker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,7 @@ export default {
const type = this.type;
if (HAVE_TRIGGER_TYPES.indexOf(type) !== -1) {
if (!this.pickerVisible) {
this.showPicker();
}
this.pickerVisible = !this.pickerVisible;
}
this.$emit('focus', this);
},
Expand Down Expand Up @@ -451,7 +449,7 @@ export default {
this.$emit('input', date);
if (!visible) {
this.pickerVisible = this.picker.visible = false;
this.pickerVisible = this.picker.visible = !this.picker.visible;
}
this.picker.resetView && this.picker.resetView();
});
Expand All @@ -467,10 +465,7 @@ export default {
}
this.$nextTick(() => {
if (this.popper) {
this.popper.update();
return;
}
if (this.popper) return;
this.popper = new Popper(this.$refs.reference, this.picker.$el, {
gpuAcceleration: false,
Expand Down
10 changes: 8 additions & 2 deletions packages/date-picker/src/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,15 @@ export const merge = function(target) {
return target;
};

export const formatDate = function(date, format) {
export const toDate = function(date) {
date = new Date(date);
if (isNaN(date.getTime())) return '';
if (isNaN(date.getTime())) return null;
return date;
};

export const formatDate = function(date, format) {
date = toDate(date);
if (!date) return '';
return dateUtil.format(date, format || 'yyyy-MM-dd');
};

Expand Down

0 comments on commit 2cf9663

Please sign in to comment.