Skip to content

Commit 6069662

Browse files
fix date input field require validation
1 parent 3bccf4a commit 6069662

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

client/packages/lowcoder/src/comps/comps/dateComp/dateComp.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ const timeValidationFields = (children: CommonChildrenType, dateType: PickerMode
119119
function validate(
120120
props: RecordConstructorToView<typeof validationChildren> & {
121121
value: { value: string };
122+
showTime: boolean;
122123
}
123124
): {
124125
validateStatus: "success" | "warning" | "error";
@@ -127,10 +128,9 @@ function validate(
127128
if (props.customRule) {
128129
return { validateStatus: "error", help: props.customRule };
129130
}
131+
const currentDateTime = dayjs(props.value.value, DateParser);
130132

131-
const currentDateTime = dayjs(dayjs(props.value.value), DATE_TIME_FORMAT);
132-
133-
if (props.required && !currentDateTime.isValid()) {
133+
if (props.required && (props.value.value === '' || !currentDateTime.isValid())) {
134134
return { validateStatus: "error", help: trans("prop.required") };
135135
}
136136

@@ -169,6 +169,7 @@ export const datePickerControl = new UICompBuilder(childrenMap, (props) => {
169169
if (props.value.value !== '') {
170170
time = dayjs(props.value.value, DateParser);
171171
}
172+
172173
return props.label({
173174
required: props.required,
174175
style: props.style,

client/packages/lowcoder/src/util/dateTimeUtils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,11 @@ export const TIME_12_FORMAT = "HH:mm:ss:a";
7171
export const TIME_FORMAT_MINUTES = "HH:mm"
7272
export const DATE_FORMAT = "YYYY-MM-DD";
7373
export const DATE_FORMAT_EN = "MM/DD/YYYY";
74+
export const DATE_FORMAT_EN_2 = "M/D/YYYY";
7475
export const DATE_TIME_FORMAT = "YYYY-MM-DD HH:mm:ss";
7576
export const DATE_TIME_12_FORMAT = "YYYY-MM-DD HH:mm:ss:a";
7677
export const TIMESTAMP_FORMAT = "x";
77-
export const DateParser = [DATE_TIME_FORMAT, DATE_TIME_12_FORMAT, DATE_FORMAT, TIMESTAMP_FORMAT, DATE_FORMAT_EN];
78+
export const DateParser = [DATE_TIME_FORMAT, DATE_TIME_12_FORMAT, DATE_FORMAT, TIMESTAMP_FORMAT, DATE_FORMAT_EN, DATE_FORMAT_EN_2];
7879
export const TimeParser = [TIME_12_FORMAT, TIME_FORMAT, TIMESTAMP_FORMAT];
7980
export type PickerMode = "date" | "week" | "month" | "quarter" | "year";
8081

0 commit comments

Comments
 (0)