Skip to content

Commit

Permalink
Merge pull request #3403 from ingef/fix-disclosure-default-validation
Browse files Browse the repository at this point in the history
Re-trigger validation of default values after applying them to disclosure list field
  • Loading branch information
Kadrian authored Apr 22, 2024
2 parents 9f10eb9 + 65dc5fd commit f9fcec1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
8 changes: 7 additions & 1 deletion frontend/src/js/external-forms/form/Field.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { memo } from "react";
import { Control, UseFormRegister, UseFormSetValue } from "react-hook-form";
import {
Control,
UseFormRegister,
UseFormSetValue,
UseFormTrigger,
} from "react-hook-form";

import type { SelectOptionT } from "../../api/types";
import { useDatasetId } from "../../dataset/selectors";
Expand Down Expand Up @@ -35,6 +40,7 @@ const Field = ({
register: UseFormRegister<DynamicFormValues>;
setValue: UseFormSetValue<DynamicFormValues>;
control: Control<DynamicFormValues>;
trigger: UseFormTrigger<DynamicFormValues>;
}) => {
const datasetId = useDatasetId();
const { locale, availableDatasets } = commonProps;
Expand Down
1 change: 1 addition & 0 deletions frontend/src/js/external-forms/form/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const Form = memo(({ config, datasetOptions, methods }: Props) => {
h1Index={h1Index}
register={methods.register}
control={methods.control}
trigger={methods.trigger}
field={field}
setValue={methods.setValue}
availableDatasets={datasetOptions}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,10 @@ export const DisclosureListField = ({
// to useForm above. But somehow, it doesn't. So we have to
// manually apply the default value here.
replace(defaultValue);
setTimeout(() => commonProps.trigger(), 100);
}
},
[fields.length, replace, defaultValue],
[fields.length, replace, defaultValue, commonProps],
);

if (field.fields.length === 0) return null;
Expand Down

0 comments on commit f9fcec1

Please sign in to comment.