Commit 34867ff9a95eee6883098b7e78563df330e7c095
1 parent
8d532306
normalise empty initial values
Showing
1 changed file
with
11 additions
and
1 deletions
Show diff stats
src/components/date-picker/picker.vue
| ... | ... | @@ -74,6 +74,8 @@ |
| 74 | 74 | |
| 75 | 75 | const prefixCls = 'ivu-date-picker'; |
| 76 | 76 | |
| 77 | + const isEmptyArray = val => val.reduce((isEmpty, str) => isEmpty && !str || (typeof str === 'string' && str.trim() === ''), true); | |
| 78 | + | |
| 77 | 79 | export default { |
| 78 | 80 | name: 'CalendarPicker', |
| 79 | 81 | mixins: [ Emitter ], |
| ... | ... | @@ -155,6 +157,10 @@ |
| 155 | 157 | type: [Date, String, Array], |
| 156 | 158 | validator(val){ |
| 157 | 159 | if (Array.isArray(val)){ |
| 160 | + // check if its empty values | |
| 161 | + if (isEmptyArray(val)) return true; | |
| 162 | + | |
| 163 | + // check if its valid value | |
| 158 | 164 | const [start, end] = val.map(v => new Date(v)); |
| 159 | 165 | return !isNaN(start.getTime()) && !isNaN(end.getTime()); |
| 160 | 166 | } else { |
| ... | ... | @@ -170,11 +176,15 @@ |
| 170 | 176 | } |
| 171 | 177 | }, |
| 172 | 178 | data(){ |
| 179 | + | |
| 180 | + const isRange = this.type.includes('range'); | |
| 181 | + const emptyArray = isRange ? [null, null] : [null]; | |
| 182 | + const initialValue = isEmptyArray(this.value || []) ? emptyArray : this.parseDate(this.value); | |
| 173 | 183 | return { |
| 174 | 184 | prefixCls: prefixCls, |
| 175 | 185 | showClose: false, |
| 176 | 186 | visible: false, |
| 177 | - internalValue: this.parseDate(this.value), | |
| 187 | + internalValue: initialValue, | |
| 178 | 188 | disableClickOutSide: false, // fixed when click a date,trigger clickoutside to close picker |
| 179 | 189 | disableCloseUnderTransfer: false, // transfer 模式下,点击Drop也会触发关闭, |
| 180 | 190 | selectionMode: this.onSelectionModeChange(this.type), | ... | ... |