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