Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check input value on keyup, set date if valid input #5

Merged
merged 1 commit into from
Mar 16, 2021
Merged
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
21 changes: 21 additions & 0 deletions src/litepie-datepicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
v-bind="$attrs"
v-model="value"
:placeholder="givenPlaceholder"
@keyup="keyUp"
/>
<span
class="absolute inset-y-0 right-0 inline-flex items-center rounded-md overflow-hidden"
Expand Down Expand Up @@ -671,6 +672,25 @@ export default /*#__PURE__*/ defineComponent({
LitepieInputRef.value && LitepieInputRef.value.focus();
};

const keyUp = () => {
if (asRange()) {
const [s, e] = value.value.split(props.separator);
const [sd, ed] = [
dayjs(s, props.formatter.date, true),
dayjs(e, props.formatter.date, true)
];
if (sd.isValid() && ed.isValid()) {
setDate(sd);
setDate(ed);
}
} else {
const d = dayjs(value.value, props.formatter.date, true);
if (d.isValid()) {
setDate(d);
}
}
};

const setDate = (date, asNext) => {
if (asRange()) {
if (previous.value) {
Expand Down Expand Up @@ -1472,6 +1492,7 @@ export default /*#__PURE__*/ defineComponent({
asRange,
show,
hide,
keyUp,
setDate,
setHours,
setMinutes,
Expand Down