Skip to content

Commit

Permalink
fix: prevent editing non numeric parts
Browse files Browse the repository at this point in the history
  • Loading branch information
logaretm committed Jan 26, 2025
1 parent cb322c0 commit 861c0ea
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/core/src/useDateTimeField/useDateTimeSegment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export function useDateTimeSegment(_props: Reactivify<DateTimeSegmentProps>) {
getType: () => toValue(props.type),
});

const isNumeric = computed(() => parser.isValidNumberPart(toValue(props.value)));

let currentInput = '';

const handlers = {
Expand All @@ -64,6 +66,10 @@ export function useDateTimeSegment(_props: Reactivify<DateTimeSegmentProps>) {
}

blockEvent(evt);
if (!isNumeric.value) {
return;
}

const nextValue = currentInput + evt.data;
currentInput = nextValue;

Expand Down
2 changes: 1 addition & 1 deletion packages/playground/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import DateField from '@/components/DateField.vue';
label="Date"
:format-options="{
day: '2-digit',
month: '2-digit',
month: 'long',
year: 'numeric',
hour: '2-digit',
hour12: true,
Expand Down

0 comments on commit 861c0ea

Please sign in to comment.