Skip to content

Commit

Permalink
feat: alllow passing date in string format
Browse files Browse the repository at this point in the history
  • Loading branch information
NetCZ committed Apr 22, 2020
1 parent 20e3f94 commit 579feb5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import moment from 'moment';
import Pikaday from 'pikaday';
import isDate from 'lodash/isDate';
import isString from 'lodash/isString';

import 'pikaday/css/pikaday.css';

Expand All @@ -15,7 +16,7 @@ export default {
inheritAttrs: false,
props: {
value: {
validator(value: typeof undefined | null | Date | Event): boolean {
validator(value: typeof undefined | null | Date | Event | string): boolean {
const allowedTypes: Array<typeof undefined | null> = [undefined, null];

if (isEvent(value)) {
Expand All @@ -26,6 +27,10 @@ export default {
return true;
}

if(isString(value) && moment(value).isValid()) {
return true;
}

for (const type of allowedTypes) {
const allowed: boolean = value === type || typeof value === type;

Expand Down

0 comments on commit 579feb5

Please # to comment.