Reset the form when the type is changed (#2189)

This commit is contained in:
Erik Jan de Wit 2022-03-07 15:27:10 +01:00 committed by GitHub
parent 663e96d000
commit dd35ccb9bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -56,7 +56,7 @@ export default function ExecutorForm() {
ClientProfileRepresentation[]
>([]);
const [profiles, setProfiles] = useState<ClientProfileRepresentation[]>([]);
const form = useForm({ defaultValues, shouldUnregister: false });
const form = useForm({ defaultValues });
const { control, reset, handleSubmit } = form;
const editMode = !!executorName;
@ -188,13 +188,13 @@ export default function ExecutorForm() {
name="executor"
defaultValue=""
control={control}
render={({ onChange, value }) => (
render={({ value }) => (
<Select
toggleId="kc-executor"
placeholderText="Select an executor"
onToggle={(isOpen) => setSelectExecutorTypeOpen(isOpen)}
onSelect={(_, value) => {
onChange(value.toString());
reset({ ...defaultValues, executor: value.toString() });
const selectedExecutor = executorTypes?.filter(
(type) => type.id === value
);
@ -225,10 +225,11 @@ export default function ExecutorForm() {
/>
</FormGroup>
<FormProvider {...form}>
<DynamicComponents properties={executorProperties} />
{editMode && (
<DynamicComponents properties={editedProfileExecutors!} />
)}
<DynamicComponents
properties={
editMode ? editedProfileExecutors! : executorProperties
}
/>
</FormProvider>
{!globalProfile && (
<ActionGroup>
@ -258,10 +259,7 @@ export default function ExecutorForm() {
<div className="kc-backToProfile">
<Button
component={(props) => (
<Link
{...props}
to={toClientProfile({ realm, profileName })}
></Link>
<Link {...props} to={toClientProfile({ realm, profileName })} />
)}
variant="primary"
>