Skip to content

Commit 613890f

Browse files
committed
unregister signature field when unomunting to prevent submission block when field is hidden
1 parent 4aaaed7 commit 613890f

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

frontend/src/templates/Field/Signature/SignatureField.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const SignatureField = ({
3232
isHighContrast,
3333
}: SignatureFieldProps): JSX.Element => {
3434
const formContext = useFormContext<SignatureFieldInput>()
35-
const { getValues, setValue } = formContext
35+
const { register, unregister, setValue } = formContext
3636
const { isSubmitting, isValid, errors } = useFormState<SignatureFieldInput>()
3737
const [showSignaturePlaceholder, setShowSignaturePlaceholder] = useState(true)
3838

@@ -55,8 +55,13 @@ export const SignatureField = ({
5555
)
5656

5757
useEffect(() => {
58-
formContext.register(schema._id, signatureValidationRules)
59-
}, [formContext, schema._id, signatureValidationRules])
58+
register(schema._id, signatureValidationRules)
59+
60+
// when unmounting, unregister the field so that submission will not be blocked by signature validation errors
61+
return () => {
62+
unregister(schema._id)
63+
}
64+
}, [register, schema._id, signatureValidationRules, unregister])
6065

6166
// perfect freehand variables
6267
const pfCanvasRef = useRef<HTMLCanvasElement>(null)

0 commit comments

Comments
 (0)