2020-03-28 00:28:30 +13:00
|
|
|
<script>
|
2020-03-28 05:58:32 +13:00
|
|
|
import Select from "../../../common/Select.svelte"
|
2020-03-28 00:28:30 +13:00
|
|
|
|
2020-03-28 05:58:32 +13:00
|
|
|
export let record
|
|
|
|
export let field
|
|
|
|
export let errors
|
2020-03-28 00:28:30 +13:00
|
|
|
|
2020-03-28 05:58:32 +13:00
|
|
|
$: isDropdown =
|
|
|
|
field.type === "string" &&
|
|
|
|
field.typeOptions.values &&
|
|
|
|
field.typeOptions.values.length > 0
|
2020-03-28 00:28:30 +13:00
|
|
|
|
2020-03-28 05:58:32 +13:00
|
|
|
$: isNumber = field.type === "number"
|
2020-03-28 00:28:30 +13:00
|
|
|
|
2020-03-28 05:58:32 +13:00
|
|
|
$: isText = field.type === "string" && !isDropdown
|
2020-03-28 00:28:30 +13:00
|
|
|
|
2020-03-28 05:58:32 +13:00
|
|
|
$: isCheckbox = field.type === "bool"
|
2020-03-28 00:28:30 +13:00
|
|
|
|
2020-03-28 05:58:32 +13:00
|
|
|
$: isError = errors && errors.some(e => e.field && e.field === field.name)
|
2020-03-28 00:28:30 +13:00
|
|
|
|
2020-03-28 05:58:32 +13:00
|
|
|
$: isDatetime = field.type === "datetime"
|
2020-03-28 00:28:30 +13:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<div class="uk-margin">
|
|
|
|
{#if !isCheckbox}
|
2020-03-28 05:58:32 +13:00
|
|
|
<label class="uk-form-label" for={field.name}>{field.label}</label>
|
2020-03-28 00:28:30 +13:00
|
|
|
{/if}
|
|
|
|
<div class="uk-form-controls">
|
|
|
|
{#if isDropdown}
|
|
|
|
<Select bind:value={record[field.name]}>
|
2020-03-28 05:58:32 +13:00
|
|
|
<option value="" />
|
2020-03-28 00:28:30 +13:00
|
|
|
{#each field.typeOptions.values as val}
|
|
|
|
<option value={val}>{val}</option>
|
|
|
|
{/each}
|
2020-03-28 05:58:32 +13:00
|
|
|
</Select>
|
2020-03-28 00:28:30 +13:00
|
|
|
{:else if isText}
|
|
|
|
<input
|
|
|
|
class="uk-input"
|
|
|
|
class:uk-form-danger={isError}
|
|
|
|
id={field.name}
|
|
|
|
type="text"
|
|
|
|
bind:value={record[field.name]} />
|
|
|
|
{:else if isNumber}
|
|
|
|
<input
|
|
|
|
class="uk-input"
|
|
|
|
class:uk-form-danger={isError}
|
|
|
|
type="number"
|
|
|
|
bind:value={record[field.name]} />
|
|
|
|
{:else if isDatetime}
|
|
|
|
<input
|
|
|
|
class="uk-input"
|
|
|
|
class:uk-form-danger={isError}
|
|
|
|
type="date"
|
|
|
|
bind:value={record[field.name]} />
|
|
|
|
{:else if isCheckbox}
|
|
|
|
<label>
|
|
|
|
<input
|
|
|
|
class="uk-checkbox"
|
|
|
|
class:uk-form-danger={isError}
|
|
|
|
type="checkbox"
|
2020-03-28 05:58:32 +13:00
|
|
|
bind:checked={record[field.name]} />
|
|
|
|
{field.label}
|
2020-03-28 00:28:30 +13:00
|
|
|
</label>
|
|
|
|
{/if}
|
|
|
|
</div>
|
2020-03-28 05:58:32 +13:00
|
|
|
</div>
|