Skip to content

Commit

Permalink
fixed missing seconds on date-time filters
Browse files Browse the repository at this point in the history
  • Loading branch information
danigargar committed Aug 9, 2024
1 parent 1f86fb8 commit 83f508b
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion library/src/services/form/Field/TextField/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ export const TextField = (props: TextFieldProps) => {
const labelId = `${name}-label`;
const maxRows = multiline ? 6 : undefined;

const fixDateTime = (value: string) => {
const haveMissingSeconds = value.length === 16;

return haveMissingSeconds ? value.concat(':00') : value;
};

type passThroughPropsType = Partial<OutlinedInputProps>;
const passThroughProps: passThroughPropsType = {};

Expand All @@ -64,6 +70,19 @@ export const TextField = (props: TextFieldProps) => {
passThroughProps.onClick = onClick;
}

passThroughProps.onChange = (event) => {
const { target } = event;

if (type === 'datetime-local') {
const fixedDate = fixDateTime(target.value);
event.target = { ...target, ...{ value: fixedDate } };
}

if (onChange) {
onChange(event);
}
};

return (
<FormControl
variant='standard'
Expand Down Expand Up @@ -99,7 +118,6 @@ export const TextField = (props: TextFieldProps) => {
defaultValue={defaultValue}
value={value}
disabled={disabled}
onChange={onChange}
onBlur={onBlur}
error={error}
className='input-field'
Expand Down

0 comments on commit 83f508b

Please sign in to comment.