Skip to content

Commit c2fba31

Browse files
eluce2claude
andcommitted
fix(typegen): use setValue with shouldDirty for inherit select options
field.onChange(undefined) doesn't mark form as dirty in react-hook-form. Using setValue with shouldDirty: true fixes the issue. Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent affdd65 commit c2fba31

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

packages/typegen/web/src/components/LayoutItemEditor.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ interface LayoutItemEditorProps {
1616
}
1717

1818
export function LayoutItemEditor({ configIndex, layoutIndex, onRemove }: LayoutItemEditorProps) {
19-
const { control, watch } = useFormContext<{ config: SingleConfig[] }>();
19+
const { control, watch, setValue } = useFormContext<{ config: SingleConfig[] }>();
2020
const schemaName = watch(`config.${configIndex}.layouts.${layoutIndex}.schemaName`);
2121
const layoutName = watch(`config.${configIndex}.layouts.${layoutIndex}.layoutName`);
2222

@@ -71,7 +71,15 @@ export function LayoutItemEditor({ configIndex, layoutIndex, onRemove }: LayoutI
7171
</FormLabel>
7272
<FormControl>
7373
<Select
74-
onValueChange={(val) => field.onChange(val === "__default__" ? undefined : val)}
74+
onValueChange={(val) => {
75+
if (val === "__default__") {
76+
setValue(`config.${configIndex}.layouts.${layoutIndex}.valueLists`, undefined, {
77+
shouldDirty: true,
78+
});
79+
} else {
80+
field.onChange(val);
81+
}
82+
}}
7583
value={field.value ?? "__default__"}
7684
>
7785
<SelectTrigger>
@@ -120,7 +128,9 @@ export function LayoutItemEditor({ configIndex, layoutIndex, onRemove }: LayoutI
120128
<Select
121129
onValueChange={(val) => {
122130
if (val === "__default__") {
123-
field.onChange(undefined);
131+
setValue(`config.${configIndex}.layouts.${layoutIndex}.generateClient`, undefined, {
132+
shouldDirty: true,
133+
});
124134
} else {
125135
field.onChange(val === "true");
126136
}

packages/typegen/web/src/components/metadata-fields-dialog/TableOptionsForm.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export function TableOptionsForm({
2323
open,
2424
topLevelIncludeAllFieldsByDefault,
2525
}: TableOptionsFormProps) {
26-
const { control } = useFormContext<{ config: SingleConfig[] }>();
26+
const { control, setValue } = useFormContext<{ config: SingleConfig[] }>();
2727

2828
// Get the field names for the form fields
2929
const variableNameFieldName =
@@ -92,7 +92,7 @@ export function TableOptionsForm({
9292
<Select
9393
onValueChange={(val) => {
9494
if (val === "__default__") {
95-
field.onChange(undefined);
95+
setValue(alwaysOverrideFieldNamesFieldName, undefined, { shouldDirty: true });
9696
} else {
9797
field.onChange(val === "true");
9898
}
@@ -140,7 +140,7 @@ export function TableOptionsForm({
140140
<Select
141141
onValueChange={(val) => {
142142
if (val === "__default__") {
143-
field.onChange(undefined);
143+
setValue(reduceMetadataFieldName, undefined, { shouldDirty: true });
144144
} else {
145145
field.onChange(val === "true");
146146
}
@@ -189,7 +189,7 @@ export function TableOptionsForm({
189189
<Select
190190
onValueChange={(val) => {
191191
if (val === "__default__") {
192-
field.onChange(undefined);
192+
setValue(includeAllFieldsByDefaultFieldName, undefined, { shouldDirty: true });
193193
} else {
194194
field.onChange(val === "true");
195195
}

0 commit comments

Comments
 (0)