Page MenuHomeSealhub

component-input-boolean.ts
No OneTemporary

Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None

component-input-boolean.ts

import type { Boolean as BooleanArgument } from "@sealcode/jdd";
import { printArgPath } from "./print-arg-path.js";
export function ComponentCheckbox({
arg_path,
value,
onchange,
}: {
arg_path: string[];
arg: BooleanArgument;
value: boolean;
onchange?: string;
}) {
const if_checked = value ? "checked" : "";
return /* HTML */ `<div
id=${`component-input-boolean-${arg_path.join("-")}`}
>
<label style="display: flex;flex-flow: row;">
${
/* JDD sends the values of the fields from the form and then they are merged with the previous state of the form.
HTML does not send any value for a checkbox that is unchecked — so we don't get a chance to parse it.
To overcome it, we always add a hidden input that sets the value to "false"
if the checkbox is unchecked, then only the "false" value gets sent
if the checkbox is checked, then two values are sent under the same name, and the value is parsed as an array:
["false", "on"]
*/ ""
}
<input
type="hidden"
name="${`$${printArgPath(arg_path)}`}"
value="false"
/>
<input
type="checkbox"
data-controller="autosubmit"
name="${`$${printArgPath(arg_path)}`}"
onchange="${onchange || ""}"
${if_checked}
/>
${arg_path.at(-1) || ""}
</label>
</div>`;
}

File Metadata

Mime Type
application/javascript
Expires
Fri, Nov 27, 18:30 (1 d, 3 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1229398
Default Alt Text
component-input-boolean.ts (1 KB)

Event Timeline