2020-06-02 09:55:44 +12:00
|
|
|
<script>
|
|
|
|
import { backendUiStore } from "builderStore"
|
2020-08-31 02:28:46 +12:00
|
|
|
import { Input, Label } from "@budibase/bbui"
|
2020-06-02 09:55:44 +12:00
|
|
|
|
|
|
|
export let value
|
2020-09-17 00:55:28 +12:00
|
|
|
$: value = value || {}
|
|
|
|
$: model = $backendUiStore.models.find(model => model._id === value?.modelId)
|
|
|
|
$: schemaFields = Object.keys(model?.schema ?? {})
|
2020-09-03 23:02:15 +12:00
|
|
|
|
|
|
|
function setParsedValue(evt, field) {
|
2020-09-17 00:55:28 +12:00
|
|
|
const fieldSchema = model?.schema[field]
|
|
|
|
if (fieldSchema) {
|
|
|
|
if (fieldSchema.type === "number") {
|
|
|
|
value[field] = parseInt(evt.target.value)
|
|
|
|
return
|
|
|
|
}
|
2020-09-03 23:02:15 +12:00
|
|
|
}
|
|
|
|
value[field] = evt.target.value
|
|
|
|
}
|
2020-06-02 09:55:44 +12:00
|
|
|
</script>
|
|
|
|
|
2020-09-10 18:46:01 +12:00
|
|
|
<div class="block-field">
|
2020-09-17 00:55:28 +12:00
|
|
|
<select class="budibase__input" bind:value={value.modelId}>
|
2020-09-12 08:14:58 +12:00
|
|
|
<option value="">Choose an option</option>
|
2020-08-31 01:49:25 +12:00
|
|
|
{#each $backendUiStore.models as model}
|
2020-09-12 08:14:58 +12:00
|
|
|
<option value={model._id}>{model.name}</option>
|
2020-08-31 01:49:25 +12:00
|
|
|
{/each}
|
|
|
|
</select>
|
2020-06-02 09:55:44 +12:00
|
|
|
</div>
|
|
|
|
|
2020-09-14 22:51:52 +12:00
|
|
|
{#if schemaFields.length}
|
2020-08-23 08:34:46 +12:00
|
|
|
<div class="bb-margin-xl block-field">
|
2020-09-14 22:51:52 +12:00
|
|
|
{#each schemaFields as field}
|
2020-09-17 00:55:28 +12:00
|
|
|
<div class="bb-margin-xl capitalise">
|
2020-09-03 23:02:15 +12:00
|
|
|
<Input
|
|
|
|
thin
|
|
|
|
value={value[field]}
|
|
|
|
label={field}
|
|
|
|
on:change={e => setParsedValue(e, field)} />
|
2020-06-02 09:55:44 +12:00
|
|
|
</div>
|
|
|
|
{/each}
|
|
|
|
</div>
|
|
|
|
{/if}
|
2020-09-17 00:55:28 +12:00
|
|
|
|
|
|
|
<style>
|
|
|
|
.capitalise :global(label) {
|
|
|
|
text-transform: capitalize !important;
|
|
|
|
}
|
|
|
|
</style>
|