2021-01-28 17:31:55 +01:00
|
|
|
<script>
|
2021-04-16 12:32:41 +02:00
|
|
|
import { CoreCheckbox } from "@budibase/bbui"
|
2021-02-05 11:53:25 +01:00
|
|
|
import Field from "./Field.svelte"
|
2021-01-28 17:31:55 +01:00
|
|
|
|
|
|
|
export let field
|
|
|
|
export let label
|
|
|
|
export let text
|
2021-02-17 16:16:44 +01:00
|
|
|
export let disabled = false
|
2021-08-03 20:54:32 +02:00
|
|
|
export let size
|
2021-08-10 15:37:14 +02:00
|
|
|
export let validation
|
2021-08-04 15:32:58 +02:00
|
|
|
export let defaultValue
|
2021-01-28 17:31:55 +01:00
|
|
|
|
|
|
|
let fieldState
|
|
|
|
let fieldApi
|
2021-08-04 15:32:58 +02:00
|
|
|
|
|
|
|
const isTruthy = value => {
|
|
|
|
if (!value) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if (value === true) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if (typeof value === "string" && value.toLowerCase() === "true") {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
2021-01-28 17:31:55 +01:00
|
|
|
</script>
|
|
|
|
|
2021-02-05 11:53:25 +01:00
|
|
|
<Field
|
2021-02-01 12:14:24 +01:00
|
|
|
{label}
|
|
|
|
{field}
|
2021-02-17 16:16:44 +01:00
|
|
|
{disabled}
|
2021-08-10 15:37:14 +02:00
|
|
|
{validation}
|
2021-08-04 15:32:58 +02:00
|
|
|
defaultValue={isTruthy(defaultValue)}
|
2021-02-05 11:53:25 +01:00
|
|
|
type="boolean"
|
2021-02-01 12:14:24 +01:00
|
|
|
bind:fieldState
|
|
|
|
bind:fieldApi
|
2021-05-04 12:04:42 +02:00
|
|
|
>
|
2021-01-28 17:31:55 +01:00
|
|
|
{#if fieldState}
|
2021-04-16 12:32:41 +02:00
|
|
|
<CoreCheckbox
|
2021-08-19 13:53:31 +02:00
|
|
|
value={fieldState.value}
|
|
|
|
disabled={fieldState.disabled}
|
|
|
|
error={fieldState.error}
|
|
|
|
id={fieldState.fieldId}
|
2021-08-03 21:36:42 +02:00
|
|
|
{size}
|
2021-05-04 12:32:22 +02:00
|
|
|
on:change={e => fieldApi.setValue(e.detail)}
|
2021-05-04 12:04:42 +02:00
|
|
|
{text}
|
|
|
|
/>
|
2021-01-28 17:31:55 +01:00
|
|
|
{/if}
|
2021-02-05 11:53:25 +01:00
|
|
|
</Field>
|