Skip to content

Commit

Permalink
Improved native date support in bootstrap Input control
Browse files Browse the repository at this point in the history
  • Loading branch information
gius committed Dec 19, 2020
1 parent d38188b commit c0997ed
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions packages/bootstrap/src/controls/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function formatValueForControl(value: any) {
return "";
}

if (value instanceof Date) {
if (value instanceof Date && !isNaN(value.valueOf())) {
return value.toISOString().substring(0, 10);
}

Expand Down Expand Up @@ -69,10 +69,15 @@ export class Input<TTarget, TOtherProps = unknown> extends ValidationControlBase
}

private setDate(value: string) {
if (value) {
this.setValue(new Date(value));
} else {
this.setValue(value === "" ? undefined : value);
// if the input is manual (safari), do not parse the date until at least yyyy-mm- is filled
if (value && value.length >= 8) {
const date = new Date(value);
if (!isNaN(date.valueOf())) {
this.setValue(date);
return;
}
}

this.setValue(value === "" ? undefined : value);
}
}

0 comments on commit c0997ed

Please sign in to comment.