fix(housekeeping): retain unchecked command fields

This commit is contained in:
Simo committed 2026-09-02 19:46:19 +02:00
1 parent 3b2012e704
commit 5edaa0254c
2 files changed
+105 -4

No files matched your search

@@ -41,6 +41,7 @@ interface ContentCommandFormProps extends ContentCommandSubmission {
}
const OMIT_FIELD = Symbol("omit optional Content command field");
const UNCHECKED_CHECKBOX_VALUE = "false";
function optionalEmptyValue(field: ContentCommandField): unknown {
return field.emptyValue === null || field.emptyValue === ""
? field.emptyValue
@@ -115,7 +116,11 @@ function readSubmittedValues(
for (const field of fields) {
if (field.type === "file") continue;
const value = formData.get(field.name);
if (typeof value === "string") values[field.name] = value;
if (typeof value === "string") {
values[field.name] = value;
} else if (field.type === "checkbox" && !field.allowUnchanged) {
values[field.name] = UNCHECKED_CHECKBOX_VALUE;
}
}
if (requiresReason) {
const reason = formData.get("reason");
@@ -247,8 +252,9 @@ export function ContentCommandForm({
name={field.name}
type="checkbox"
defaultChecked={
retainedValue === "on" ||
(retainedValue === undefined && field.defaultValue === true)
retainedValue === undefined
? field.defaultValue === true
: retainedValue === "on"
}
{...fieldErrorProps}
/>{" "}