fix: form reset issue

This commit is contained in:
Nicolas Meienberger 2025-11-13 20:11:08 +01:00
parent 25b5d98a3e
commit c272c2e6db
2 changed files with 10 additions and 8 deletions

View file

@ -61,17 +61,17 @@ export const CreateRepositoryForm = ({
const { watch } = form; const { watch } = form;
const watchedBackend = watch("backend"); const watchedBackend = watch("backend");
const watchedName = watch("name");
const { data: rcloneRemotes, isLoading: isLoadingRemotes } = useQuery({ const { data: rcloneRemotes, isLoading: isLoadingRemotes } = useQuery({
...listRcloneRemotesOptions(), ...listRcloneRemotesOptions(),
}); });
useEffect(() => { useEffect(() => {
if (watchedBackend && watchedBackend in defaultValuesForType) { form.reset({
form.reset({ name: watchedName, ...defaultValuesForType[watchedBackend as keyof typeof defaultValuesForType] }); name: form.getValues().name,
} ...defaultValuesForType[watchedBackend as keyof typeof defaultValuesForType],
}, [watchedBackend, watchedName, form]); });
}, [watchedBackend, form]);
const { capabilities } = useSystemInfo(); const { capabilities } = useSystemInfo();

View file

@ -50,13 +50,15 @@ export const CreateVolumeForm = ({ onSubmit, mode = "create", initialValues, for
const { watch, getValues } = form; const { watch, getValues } = form;
const watchedBackend = watch("backend"); const watchedBackend = watch("backend");
const watchedName = watch("name");
useEffect(() => { useEffect(() => {
if (mode === "create") { if (mode === "create") {
form.reset({ name: watchedName, ...defaultValuesForType[watchedBackend as keyof typeof defaultValuesForType] }); form.reset({
name: form.getValues().name,
...defaultValuesForType[watchedBackend as keyof typeof defaultValuesForType],
});
} }
}, [watchedBackend, watchedName, form.reset, mode]); }, [watchedBackend, form, mode]);
const [testMessage, setTestMessage] = useState<{ success: boolean; message: string } | null>(null); const [testMessage, setTestMessage] = useState<{ success: boolean; message: string } | null>(null);