Skip to content

Commit f13167b

Browse files
Merge pull request #208 from topcoder-platform/PROD-2441_clear-bug-hunt-form
PROD-2441 clear bug hunt form
2 parents 440c9a8 + 56f434a commit f13167b

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src-ts/lib/form/Form.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,16 @@ const Form: <ValueType extends any, RequestType extends any>(props: FormProps<Va
6262
return
6363
}
6464

65-
// validators do not clear errors on the 'initial' event,
66-
// so we call validateForm as a change here, to support the parent component sending props.formValues updates due to async data loading
65+
validateForm(formRef.current?.elements, 'initial', inputs)
66+
checkIfFormIsValid(inputs)
67+
}, [])
68+
69+
useEffect(() => {
70+
if (!formRef.current?.elements) {
71+
return
72+
}
73+
74+
// so we repeat the validation when formValues changes, to support the parent component's async data loading
6775
validateForm(formRef.current?.elements, 'change', inputs)
6876
checkIfFormIsValid(inputs)
6977
}, [props.formValues])

src-ts/tools/work/work-self-service/intake-forms/bug-hunt/BugHuntIntakeForm.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import {
55
Form,
66
FormAction,
77
FormDefinition,
8+
formGetInputFields,
89
formGetInputModel,
910
FormInputModel,
11+
formOnReset,
1012
IconOutline,
1113
InfoCard,
1214
LoadingSpinner,
@@ -66,6 +68,11 @@ const BugHuntIntakeForm: React.FC = () => {
6668
const [selectedPackage, setSelectedPackage]: [PricePackageName, Dispatch<SetStateAction<PricePackageName>>]
6769
= useState<PricePackageName>(formValues.packageType)
6870

71+
const formInputs: Array<FormInputModel> = formGetInputFields(formDef.groups)
72+
if (!workId && !challenge) {
73+
formOnReset(formInputs, formValues)
74+
}
75+
6976
useEffect(() => {
7077
const useEffectAsync: () => Promise<void> = async () => {
7178
if (!workId) {

0 commit comments

Comments
 (0)