generated from bcgov/quickstart-openshift
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ORV2-2940 - FE: UPDATE: Application contact info field validation Add (…
…#1648) Co-authored-by: GlenAOT <[email protected]>
- Loading branch information
Showing
9 changed files
with
143 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
frontend/src/common/components/form/subFormComponents/NumberInput.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@use "../CustomFormComponents"; | ||
|
||
@include CustomFormComponents.custom-form-component(".custom-number-input"); |
42 changes: 42 additions & 0 deletions
42
frontend/src/common/components/form/subFormComponents/NumberInput.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { OutlinedInput } from "@mui/material"; | ||
import { useFormContext } from "react-hook-form"; | ||
import { ORBC_FormTypes } from "../../../types/common"; | ||
import { CustomOutlinedInputProps } from "./CustomOutlinedInput"; | ||
import "./NumberInput.scss"; | ||
|
||
/** | ||
* An onRouteBC customized MUI OutlineInput component | ||
* that automatically filters out non-numeric values as the user types | ||
*/ | ||
export const NumberInput = <T extends ORBC_FormTypes>( | ||
props: CustomOutlinedInputProps<T>, | ||
): JSX.Element => { | ||
const { register, setValue } = useFormContext(); | ||
/** | ||
* Function to prevent non-numeric input as the user types | ||
*/ | ||
const filterNonNumericValue = (input?: string) => { | ||
if (!input) return ""; | ||
// only allows 0-9 inputs | ||
return input.replace(/[^\d]/g, ""); | ||
}; | ||
|
||
// Everytime the user types, update the format of the users input | ||
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
const formattedValue = filterNonNumericValue(e.target.value); | ||
setValue<string>(props.name, formattedValue, { shouldValidate: true }); | ||
}; | ||
|
||
const className = `custom-phone-input ${props.disabled ? "custom-phone-input--disabled" : ""} ${props.invalid ? "custom-phone-input--invalid" : ""}`; | ||
|
||
return ( | ||
<OutlinedInput | ||
className={className} | ||
aria-labelledby={`${props.feature}-${props.name}-label`} | ||
inputProps={props.inputProps} | ||
{...register(props.name, props.rules)} | ||
onChange={handleChange} | ||
autoComplete="tel" | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters