Add default value for boolean field

This commit is contained in:
Andrew Kingston 2021-08-04 14:32:58 +01:00
parent 9f2451e829
commit 88c22aa927
1 changed files with 15 additions and 1 deletions

View File

@ -6,19 +6,33 @@
export let label
export let text
export let disabled = false
export let defaultValue
let fieldState
let fieldApi
const isTruthy = value => {
if (!value) {
return false
}
if (value === true) {
return true
}
if (typeof value === "string" && value.toLowerCase() === "true") {
return true
}
return false
}
</script>
<Field
{label}
{field}
{disabled}
defaultValue={isTruthy(defaultValue)}
type="boolean"
bind:fieldState
bind:fieldApi
defaultValue={false}
>
{#if fieldState}
<CoreCheckbox