Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
Element
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
林焕东
Element
Commits
71a66ae2
Commit
71a66ae2
authored
May 07, 2018
by
Jiewei Qian
Committed by
杨奕
May 07, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DatePicker: fix valueEquals for array (#11017)
parent
897f2068
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
5 deletions
+77
-5
packages/date-picker/src/picker.vue
packages/date-picker/src/picker.vue
+23
-5
test/unit/specs/date-picker.spec.js
test/unit/specs/date-picker.spec.js
+54
-0
No files found.
packages/date-picker/src/picker.vue
View file @
71a66ae2
...
@@ -280,18 +280,36 @@ const formatAsFormatAndType = (value, customFormat, type) => {
...
@@ -280,18 +280,36 @@ const formatAsFormatAndType = (value, customFormat, type) => {
return
formatter
(
value
,
format
);
return
formatter
(
value
,
format
);
};
};
// only considers date-picker's value: Date or [Date, Date]
/*
* Considers:
* 1. Date object
* 2. date string
* 3. array of 1 or 2
*/
const
valueEquals
=
function
(
a
,
b
)
{
const
valueEquals
=
function
(
a
,
b
)
{
// considers Date object and string
const
dateEquals
=
function
(
a
,
b
)
{
const
aIsDate
=
a
instanceof
Date
;
const
bIsDate
=
b
instanceof
Date
;
if
(
aIsDate
&&
bIsDate
)
{
return
a
.
getTime
()
===
b
.
getTime
();
}
if
(
!
aIsDate
&&
!
bIsDate
)
{
return
a
===
b
;
}
return
false
;
};
const
aIsArray
=
a
instanceof
Array
;
const
aIsArray
=
a
instanceof
Array
;
const
bIsArray
=
b
instanceof
Array
;
const
bIsArray
=
b
instanceof
Array
;
if
(
aIsArray
&&
bIsArray
)
{
if
(
aIsArray
&&
bIsArray
)
{
if
(
a
.
length
!==
b
.
length
)
{
if
(
a
.
length
!==
b
.
length
)
{
return
false
;
return
false
;
}
}
return
a
.
every
((
item
,
index
)
=>
new
Date
(
item
).
getTime
()
===
new
Date
(
b
[
index
]).
getTime
(
));
return
a
.
every
((
item
,
index
)
=>
dateEquals
(
item
,
b
[
index
]
));
}
}
if
(
!
aIsArray
&&
!
bIsArray
)
{
if
(
!
aIsArray
&&
!
bIsArray
)
{
return
new
Date
(
a
).
getTime
()
===
new
Date
(
b
).
getTime
(
);
return
dateEquals
(
a
,
b
);
}
}
return
false
;
return
false
;
};
};
...
@@ -865,7 +883,7 @@ export default {
...
@@ -865,7 +883,7 @@ export default {
emitChange
(
val
)
{
emitChange
(
val
)
{
// determine user real change only
// determine user real change only
if
(
val
!==
this
.
valueOnOpen
)
{
if
(
!
valueEquals
(
val
,
this
.
valueOnOpen
)
)
{
this
.
$emit
(
'
change
'
,
val
);
this
.
$emit
(
'
change
'
,
val
);
this
.
dispatch
(
'
ElFormItem
'
,
'
el.form.change
'
,
val
);
this
.
dispatch
(
'
ElFormItem
'
,
'
el.form.change
'
,
val
);
this
.
valueOnOpen
=
val
;
this
.
valueOnOpen
=
val
;
...
@@ -874,7 +892,7 @@ export default {
...
@@ -874,7 +892,7 @@ export default {
emitInput
(
val
)
{
emitInput
(
val
)
{
const
formatted
=
this
.
formatToValue
(
val
);
const
formatted
=
this
.
formatToValue
(
val
);
if
(
!
valueEquals
(
this
.
value
,
formatted
)
||
this
.
type
===
'
dates
'
)
{
if
(
!
valueEquals
(
this
.
value
,
formatted
))
{
this
.
$emit
(
'
input
'
,
formatted
);
this
.
$emit
(
'
input
'
,
formatted
);
}
}
},
},
...
...
test/unit/specs/date-picker.spec.js
View file @
71a66ae2
...
@@ -1676,6 +1676,60 @@ describe('DatePicker', () => {
...
@@ -1676,6 +1676,60 @@ describe('DatePicker', () => {
},
DELAY
);
},
DELAY
);
});
});
it
(
'
change event
'
,
done
=>
{
vm
=
createVue
({
template
:
`
<el-date-picker
ref="compo"
v-model="value"
type="daterange" />`
,
data
()
{
return
{
value
:
''
};
}
},
true
);
const
spy
=
sinon
.
spy
();
vm
.
$refs
.
compo
.
$on
(
'
change
'
,
spy
);
const
input
=
vm
.
$el
.
querySelector
(
'
input
'
);
input
.
blur
();
input
.
focus
();
setTimeout
(
_
=>
{
const
picker
=
vm
.
$refs
.
compo
.
picker
;
setTimeout
(
_
=>
{
picker
.
$el
.
querySelector
(
'
td.available
'
).
click
();
setTimeout
(
_
=>
{
picker
.
$el
.
querySelector
(
'
td.available ~ td.available
'
).
click
();
setTimeout
(
_
=>
{
expect
(
spy
.
calledOnce
).
to
.
equal
(
true
);
console
.
log
(
'
first assert passed
'
);
// change event is not emitted if used does not change value
// datarange also requires proper array equality check
input
.
blur
();
input
.
focus
();
setTimeout
(
_
=>
{
const
startCell
=
picker
.
$el
.
querySelector
(
'
td.start-date
'
);
const
endCell
=
picker
.
$el
.
querySelector
(
'
td.end-date
'
);
startCell
.
click
();
setTimeout
(
_
=>
{
endCell
.
click
();
setTimeout
(
_
=>
{
expect
(
spy
.
calledOnce
).
to
.
equal
(
true
);
console
.
log
(
'
second assert passed
'
);
done
();
},
DELAY
);
},
DELAY
);
},
DELAY
);
},
DELAY
);
},
DELAY
);
},
DELAY
);
},
DELAY
);
});
describe
(
'
default value
'
,
()
=>
{
describe
(
'
default value
'
,
()
=>
{
it
(
'
single
'
,
done
=>
{
it
(
'
single
'
,
done
=>
{
let
defaultValue
=
'
2000-10-01
'
;
let
defaultValue
=
'
2000-10-01
'
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment