Skip to content

PROD-2441 clear bug hunt form #208

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

Merged
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
12 changes: 10 additions & 2 deletions src-ts/lib/form/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,16 @@ const Form: <ValueType extends any, RequestType extends any>(props: FormProps<Va
return
}

// validators do not clear errors on the 'initial' event,
// so we call validateForm as a change here, to support the parent component sending props.formValues updates due to async data loading
validateForm(formRef.current?.elements, 'initial', inputs)
checkIfFormIsValid(inputs)
}, [])

useEffect(() => {
if (!formRef.current?.elements) {
return
}

// so we repeat the validation when formValues changes, to support the parent component's async data loading
validateForm(formRef.current?.elements, 'change', inputs)
checkIfFormIsValid(inputs)
}, [props.formValues])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import {
Form,
FormAction,
FormDefinition,
formGetInputFields,
formGetInputModel,
FormInputModel,
formOnReset,
IconOutline,
InfoCard,
LoadingSpinner,
Expand Down Expand Up @@ -66,6 +68,11 @@ const BugHuntIntakeForm: React.FC = () => {
const [selectedPackage, setSelectedPackage]: [PricePackageName, Dispatch<SetStateAction<PricePackageName>>]
= useState<PricePackageName>(formValues.packageType)

const formInputs: Array<FormInputModel> = formGetInputFields(formDef.groups)
if (!workId && !challenge) {
formOnReset(formInputs, formValues)
}

useEffect(() => {
const useEffectAsync: () => Promise<void> = async () => {
if (!workId) {
Expand Down