Skip to content

Commit

Permalink
Merge branch 'main' into PIMS-2000-MandatoryCheckboxes
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarkowsky authored Sep 9, 2024
2 parents 7c66e9f + b846a88 commit 52b753b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions react-app/src/components/form/TextFormField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type TextFormFieldProps = {

const TextFormField = (props: TextFormFieldProps) => {
const { control, setValue } = useFormContext();
const { name, label, rules, numeric, isPid, defaultVal, disabled, ...restProps } = props;
const { name, label, rules, numeric, isPid, defaultVal, disabled, onBlur, ...restProps } = props;
return (
<Controller
control={control}
Expand All @@ -30,18 +30,23 @@ const TextFormField = (props: TextFormFieldProps) => {
if (numeric && parseFloat(event.currentTarget.value)) {
setValue(name, parseFloat(event.currentTarget.value));
}
}}
onChange={(event) => {
if (isPid) {
setValue(name, event.target.value.replace(/-/g, ''));
event.target.value = pidFormatter(parseInt(event.target.value.replace(/-/g, '')));
onChange(event);
}
if (onBlur) onBlur(event);
}}
onChange={(event) => {
if (isPid && (event.target.value === '' || /^[0-9-]*$/.test(event.target.value))) {
onChange(event);
return;
} else if (
numeric &&
(event.target.value === '' || /^[0-9]*\.?[0-9]{0,2}$/.test(event.target.value))
) {
onChange(event);
} else if (numeric === undefined) {
} else if (numeric === undefined && isPid === undefined) {
onChange(event);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion react-app/src/utilities/formatters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const zeroPadPID = (pid: number | string): string => {

export const pidFormatter = (pid: number | string): string => {
if (pid == null) return '';
return zeroPadPID(pid).match(/\d{3}/g).join('-');
return zeroPadPID(pid).match(/\d{3}/g).join('-').slice(0, 11);
};

export const formatNumber = (num: number) => num.toLocaleString();

0 comments on commit 52b753b

Please sign in to comment.