ui: Display bool type as checkbox

This commit is contained in:
nemunaire 2024-01-17 16:37:42 +01:00
parent e152a14475
commit 7d51a88424
3 changed files with 13 additions and 10 deletions

View File

@ -50,15 +50,17 @@
{specs.id}
{/if}
</label>
<Col md="8">
<ResourceRawInput
{edit}
{index}
{specs}
bind:value={value}
on:focus={() => dispatch("focus")}
on:blur={() => dispatch("blur")}
/>
<Col md="8" class="d-flex flex-column">
<div class="flex-fill d-flex align-items-center">
<ResourceRawInput
{edit}
{index}
{specs}
bind:value={value}
on:focus={() => dispatch("focus")}
on:blur={() => dispatch("blur")}
/>
</div>
{#if specs.description && (showDescription || (specs.choices && specs.choices.length > 0))}
<p class="text-justify" style="line-height: 1.1">
<small class="text-muted">{specs.description}</small>

View File

@ -47,6 +47,7 @@
let inputtype: InputType = "text";
$: if (specs.type && (specs.type.startsWith("uint") || specs.type.startsWith("int"))) inputtype = "number";
else if (specs.type && specs.type === "bool") inputtype = "checkbox";
let inputmin: number | undefined = undefined;
let inputmax: number | undefined = undefined;
@ -122,7 +123,6 @@
plaintext={!edit}
readonly={!edit}
required={specs.required}
style="width: initial"
bind:value={value}
on:focus={() => dispatch("focus")}
on:blur={() => dispatch("blur")}

View File

@ -27,6 +27,7 @@ export function fillUndefinedValues(value: any, spec: Field) {
if (vartype[0] == "*") vartype = vartype.substring(1);
if (spec.default !== undefined) value[spec.id] = spec.default;
else if (vartype == "bool") value[spec.id] = false;
else if (vartype == "[]uint8") value[spec.id] = "";
else if (vartype.startsWith("[]")) value[spec.id] = [];
else if (vartype != "string" && !vartype.startsWith("uint") && !vartype.startsWith("int") && vartype != "net.IP" && vartype != "common.URL" && vartype != "time.Duration" && vartype != "common.Duration") value[spec.id] = { };