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 eee7265
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions library/src/services/form/Field/TextField/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,40 @@ 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 = {};

if (onKeyDown) {
passThroughProps.onKeyDown = onKeyDown as KeyboardEventHandler<
HTMLTextAreaElement | HTMLInputElement
>;
}
}
if (onClick) {
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
Expand Down Expand Up @@ -98,8 +121,7 @@ export const TextField = (props: TextFieldProps) => {
placeholder={placeholder}
defaultValue={defaultValue}
value={value}
disabled={disabled}
onChange={onChange}
disabled={disabled}
onBlur={onBlur}
error={error}
className='input-field'
Expand Down

0 comments on commit eee7265

Please sign in to comment.