diff --git a/components/forms/SettingsSubmit.tsx b/components/forms/SettingsSubmit.tsx
index 298d4607..fc15609d 100644
--- a/components/forms/SettingsSubmit.tsx
+++ b/components/forms/SettingsSubmit.tsx
@@ -216,7 +216,6 @@ export default function SettingsSubmit({ mode = "create", submissionId, initialV
const lines = useFieldArray({ control, name: "line_settings" });
const rasters = useFieldArray({ control, name: "raster_settings" });
- // ⬇⬇⬇ Moved ABOVE the hydrate effect so they exist before being referenced
// Option lists (include current IDs to guarantee a visible option)
const mats = useOptions("material", initialValues?.mat ?? null);
const coats = useOptions("material_coating", initialValues?.mat_coat ?? null);
@@ -228,7 +227,6 @@ export default function SettingsSubmit({ mode = "create", submissionId, initialV
const conf = useOptions("laser_scan_lens_config", initialValues?.lens_conf ?? null);
const apt = useOptions("laser_scan_lens_apt", initialValues?.lens_apt ?? null);
const exp = useOptions("laser_scan_lens_exp", initialValues?.lens_exp ?? null);
- // ⬆⬆⬆
// Prefill (edit)
useEffect(() => {
@@ -258,32 +256,29 @@ export default function SettingsSubmit({ mode = "create", submissionId, initialV
});
}, [isEdit, initialValues, reset]);
- // Re-apply select values when options hydrate (fixes stubborn placeholder issue)
+ // Re-apply select values when options hydrate (forces DOM to adopt prefilled values)
useEffect(() => {
if (!isEdit || !initialValues) return;
- const ensure = (name: string, currentId: string | null | undefined, opts: Opt[]) => {
- if (!currentId) return;
- const cur = getValues(name as any);
- const curStr = cur == null ? "" : String(cur);
- if (!curStr || !opts.some((o) => String(o.id) === curStr)) {
- setValue(name as any, String(currentId), { shouldDirty: false, shouldValidate: false });
- }
+ const hydrate = (name: string, currentId: string | null | undefined, opts: Opt[]) => {
+ if (!currentId || !opts.length) return;
+ // Always nudge value back to the current id after options load
+ setValue(name as any, String(currentId), { shouldDirty: false, shouldValidate: false });
};
- ensure("mat", initialValues.mat, mats.opts);
- ensure("mat_coat", initialValues.mat_coat, coats.opts);
- ensure("mat_color", initialValues.mat_color, colors.opts);
- ensure("mat_opacity", initialValues.mat_opacity, opacs.opts);
+ hydrate("mat", initialValues.mat, mats.opts);
+ hydrate("mat_coat", initialValues.mat_coat, coats.opts);
+ hydrate("mat_color", initialValues.mat_color, colors.opts);
+ hydrate("mat_opacity", initialValues.mat_opacity, opacs.opts);
- ensure("laser_soft", initialValues.laser_soft, soft.opts);
- ensure("source", initialValues.source, srcs.opts);
+ hydrate("laser_soft", initialValues.laser_soft, soft.opts);
+ hydrate("source", initialValues.source, srcs.opts);
- ensure("lens_conf", initialValues.lens_conf, conf.opts);
- ensure("lens_apt", initialValues.lens_apt, apt.opts);
- ensure("lens_exp", initialValues.lens_exp, exp.opts);
+ hydrate("lens_conf", initialValues.lens_conf, conf.opts);
+ hydrate("lens_apt", initialValues.lens_apt, apt.opts);
+ hydrate("lens_exp", initialValues.lens_exp, exp.opts);
- ensure("lens", initialValues.lens, lens.opts);
+ hydrate("lens", initialValues.lens, lens.opts);
}, [
isEdit,
initialValues,
@@ -291,7 +286,7 @@ export default function SettingsSubmit({ mode = "create", submissionId, initialV
soft.opts, srcs.opts,
conf.opts, apt.opts, exp.opts,
lens.opts,
- getValues, setValue,
+ setValue,
]);
// Image files
@@ -453,9 +448,7 @@ export default function SettingsSubmit({ mode = "create", submissionId, initialV