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 label
export let text export let text
export let disabled = false export let disabled = false
export let defaultValue
let fieldState let fieldState
let fieldApi 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> </script>
<Field <Field
{label} {label}
{field} {field}
{disabled} {disabled}
defaultValue={isTruthy(defaultValue)}
type="boolean" type="boolean"
bind:fieldState bind:fieldState
bind:fieldApi bind:fieldApi
defaultValue={false}
> >
{#if fieldState} {#if fieldState}
<CoreCheckbox <CoreCheckbox