From d7bf8f067c827005ad20bbb000aff4297c9b9575 Mon Sep 17 00:00:00 2001 From: Xevion Date: Tue, 23 May 2023 23:40:41 -0500 Subject: [PATCH] Add onChange prop to LookupInput, add default value to 'target' in useForm hook --- src/components/form/LookupInput.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/components/form/LookupInput.tsx b/src/components/form/LookupInput.tsx index 9a67a4a..19c70d5 100644 --- a/src/components/form/LookupInput.tsx +++ b/src/components/form/LookupInput.tsx @@ -10,14 +10,17 @@ type LookupInputProps = { onRegistry?: (type: TargetType) => Promise; // When a user hits submit, this is called. onSubmit?: (props: SubmitProps) => Promise; + onChange?: (target: string) => any; }; const LookupInput: FunctionComponent = ({ isLoading, onSubmit, + onChange, }: LookupInputProps) => { - const { register, handleSubmit } = useForm({ + const { register, handleSubmit, getValues } = useForm({ defaultValues: { + target: "", followReferral: false, requestJSContact: false, }, @@ -48,7 +51,12 @@ const LookupInput: FunctionComponent = ({ disabled={isLoading} placeholder="A domain, an IP address, a TLD, an RDAP URL..." type="search" - {...register("target", { required: true })} + {...register("target", { + required: true, + onChange: () => { + if (onChange != undefined) onChange(getValues("target")); + }, + })} />