Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: switch to HTML text inputs with numeric validation #4128

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import {
YesNoEnum,
} from "@bloom-housing/shared-helpers/src/types/backend-swagger"
import SectionWithGrid from "../../../shared/SectionWithGrid"
import { fieldHasError } from "../../../../lib/helpers"

const FormHouseholdIncome = () => {
const formMethods = useFormContext()

// eslint-disable-next-line @typescript-eslint/unbound-method
const { register, setValue, watch } = formMethods
const { errors, register, getValues, setValue, trigger, watch } = formMethods

const incomePeriodValue: string = watch("application.incomePeriod")

Expand Down Expand Up @@ -62,24 +63,32 @@ const FormHouseholdIncome = () => {
<Grid.Cell>
<Field
id="incomeYear"
type="number"
type="currency"
getValues={getValues}
setValue={setValue}
name="incomeYear"
label={t("application.details.annualIncome")}
placeholder={t("t.enterAmount")}
register={register}
disabled={incomePeriodValue !== IncomePeriodEnum.perYear}
error={fieldHasError(errors?.incomeYear)}
errorMessage={t("errors.numberError")}
/>
</Grid.Cell>

<Grid.Cell>
<Field
id="incomeMonth"
type="number"
type="currency"
getValues={getValues}
setValue={setValue}
name="incomeMonth"
label={t("application.details.monthlyIncome")}
placeholder={t("t.enterAmount")}
register={register}
disabled={incomePeriodValue !== IncomePeriodEnum.perMonth}
error={fieldHasError(errors?.incomeMonth)}
errorMessage={t("errors.numberError")}
/>
</Grid.Cell>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ const UnitForm = ({ onSubmit, onClose, defaultUnit, nextId, draft }: UnitFormPro
name={fieldName}
label={t("t.minimumIncome")}
register={register}
type="number"
type="currency"
getValues={getValues}
setValue={setValue}
prepend="$"
readerOnly
className={errors[fieldName] ? "error" : ""}
Expand Down Expand Up @@ -339,7 +341,7 @@ const UnitForm = ({ onSubmit, onClose, defaultUnit, nextId, draft }: UnitFormPro
}, [defaultUnit, unitTypesOptions, setValue])

// when rent type is updated we set the rent/income data to defaultUnit data for that value
// e.g. rent is fixed and swithced to percentage, then switched back we readd the old fixed data
// e.g. rent is fixed and switched to percentage, then switched back we readd the old fixed data
useEffect(() => {
if (defaultUnit) {
if (rentType === "fixed") {
Expand Down Expand Up @@ -452,7 +454,10 @@ const UnitForm = ({ onSubmit, onClose, defaultUnit, nextId, draft }: UnitFormPro
placeholder={t("listings.unit.squareFootage")}
register={register}
readerOnly
type="number"
type="text"
validation={{ pattern: /^[0-9.]+$/ }}
error={fieldHasError(errors?.sqFeet)}
errorMessage={t("errors.numberError")}
/>
</FieldValue>

Expand Down Expand Up @@ -589,8 +594,12 @@ const UnitForm = ({ onSubmit, onClose, defaultUnit, nextId, draft }: UnitFormPro
label={t("t.monthlyMinimumIncome")}
placeholder="0.00"
register={register}
type="number"
type="currency"
getValues={getValues}
setValue={setValue}
prepend="$"
error={fieldHasError(errors?.monthlyIncomeMin)}
errorMessage={t("errors.numberError")}
/>
</Grid.Cell>

Expand All @@ -601,8 +610,12 @@ const UnitForm = ({ onSubmit, onClose, defaultUnit, nextId, draft }: UnitFormPro
label={t("listings.unit.monthlyRent")}
placeholder="0.00"
register={register}
type="number"
type="currency"
getValues={getValues}
setValue={setValue}
prepend="$"
error={fieldHasError(errors?.monthlyRent)}
errorMessage={t("errors.numberError")}
/>
</Grid.Cell>
</>
Expand All @@ -615,7 +628,10 @@ const UnitForm = ({ onSubmit, onClose, defaultUnit, nextId, draft }: UnitFormPro
label={t("listings.unit.%incomeRent")}
placeholder={t("listings.unit.percentage")}
register={register}
type="number"
type="text"
validation={{ pattern: /^[0-9.]+$/ }}
error={fieldHasError(errors?.monthlyRentAsPercentOfIncome)}
errorMessage={t("errors.numberError")}
/>
</Grid.Cell>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const AdditionalFees = (props: AdditionalFeesProps) => {
const formMethods = useFormContext()
const { profile } = useContext(AuthContext)
// eslint-disable-next-line @typescript-eslint/unbound-method
const { register, watch, errors, clearErrors } = formMethods
const { register, watch, errors, clearErrors, getValues, setValue } = formMethods

const jurisdiction = watch("jurisdiction.id")

Expand Down Expand Up @@ -47,6 +47,8 @@ const AdditionalFees = (props: AdditionalFeesProps) => {
id={"applicationFee"}
register={register}
type={"currency"}
getValues={getValues}
setValue={setValue}
prepend={"$"}
placeholder={"0.00"}
/>
Expand All @@ -58,6 +60,8 @@ const AdditionalFees = (props: AdditionalFeesProps) => {
id={"depositMin"}
register={register}
type={"currency"}
getValues={getValues}
setValue={setValue}
prepend={"$"}
placeholder={"0.00"}
error={fieldHasError(errors?.depositMin)}
Expand All @@ -74,6 +78,8 @@ const AdditionalFees = (props: AdditionalFeesProps) => {
id={"depositMax"}
register={register}
type={"currency"}
getValues={getValues}
setValue={setValue}
prepend={"$"}
placeholder={"0.00"}
error={fieldHasError(errors?.depositMax)}
Expand Down
4 changes: 2 additions & 2 deletions sites/partners/src/components/settings/PreferenceDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -704,10 +704,10 @@ const PreferenceDrawer = ({
name="radiusSize"
label={t("settings.preferenceValidatingAddress.howManyMiles")}
register={register}
validation={{ required: true, min: 0 }}
validation={{ required: true, min: 0, pattern: /^[0-9.]+$/ }}
error={errors.radiusSize}
errorMessage={t("errors.requiredFieldError")}
type="number"
type="text"
readerOnly
defaultValue={optionData?.radiusSize ?? null}
dataTestId={"preference-option-radius-size"}
Expand Down