fix bug with changing types

This commit is contained in:
Martin McKeaveney 2020-08-20 15:49:18 +01:00
parent d547604178
commit 3d853677bd
3 changed files with 25 additions and 145 deletions

View File

@ -46,6 +46,7 @@
const { type, constraints } = fieldDefinitions[
event.target.value.toUpperCase()
]
field.type = type
field.constraints = constraints
}
@ -58,9 +59,9 @@
secondary
thin
on:change={handleFieldConstraints}
bind:value={field.value}>
bind:value={field.type}>
{#each Object.values(fieldDefinitions) as field}
<option value={field.value}>{field.name}</option>
<option value={field.type}>{field.name}</option>
{/each}
</Select>
@ -73,28 +74,28 @@
on:change={() => (field.constraints.presence.allowEmpty = required)} />
</div>
{#if field.value === 'string' && field.constraints}
{#if field.type === 'string' && field.constraints}
<NumberBox
label="Max Length"
bind:value={field.constraints.length.maximum} />
<ValuesList
label="Categories"
bind:values={field.constraints.inclusion} />
{:else if field.value === 'datetime' && field.constraints}
{:else if field.type === 'datetime' && field.constraints}
<DatePicker
label="Min Value"
bind:value={field.constraints.datetime.earliest} />
<DatePicker
label="Max Value"
bind:value={field.constraints.datetime.latest} />
{:else if field.value === 'number' && field.constraints}
{:else if field.type === 'number' && field.constraints}
<NumberBox
label="Min Value"
bind:value={field.constraints.numericality.greaterThanOrEqualTo} />
<NumberBox
label="Max Value"
bind:value={field.constraints.numericality.lessThanOrEqualTo} />
{:else if field.value === 'link'}
{:else if field.type === 'link'}
<div class="field">
<label>Link</label>
<select class="budibase__input" bind:value={field.modelId}>

View File

@ -21,7 +21,9 @@
$: fields = Object.keys($backendUiStore.selectedModel.schema).filter(key => {
return $backendUiStore.selectedModel.schema[key].type === "number"
})
$: views = $backendUiStore.models.flatMap(model => Object.keys(model.views))
$: views = $backendUiStore.models.flatMap(model =>
Object.keys(model.views || {})
)
function saveView() {
if (views.includes(name)) {

View File

@ -3,7 +3,6 @@ export const FIELDS = {
name: "Plain Text",
icon: "ri-text",
type: "string",
value: "string",
constraints: {
type: "string",
length: {},
@ -14,7 +13,6 @@ export const FIELDS = {
name: "Number",
icon: "ri-number-1",
type: "number",
value: "number",
constraints: {
type: "number",
presence: { allowEmpty: true },
@ -25,7 +23,6 @@ export const FIELDS = {
name: "True/False",
icon: "ri-toggle-line",
type: "boolean",
value: "boolean",
constraints: {
type: "boolean",
presence: { allowEmpty: true },
@ -40,21 +37,21 @@ export const FIELDS = {
// presence: { allowEmpty: true },
// },
// },
DATETIME: {
name: "Date/Time",
icon: "ri-calendar-event-fill",
type: "string",
value: "datetime",
constraints: {
type: "string",
length: {},
presence: { allowEmpty: true },
datetime: {
latest: "",
earliest: "",
},
},
},
// DATETIME: {
// name: "Date/Time",
// icon: "ri-calendar-event-fill",
// type: "string",
// value: "datetime",
// constraints: {
// type: "string",
// length: {},
// presence: { allowEmpty: true },
// datetime: {
// latest: "",
// earliest: "",
// },
// },
// },
// IMAGE: {
// name: "File",
// icon: "ri-image-line",
@ -83,123 +80,3 @@ export const FIELDS = {
// },
// },
}
export const BLOCKS = {
NAME: {
name: "Name",
icon: "ri-text",
type: "string",
constraints: {
type: "string",
length: {},
presence: { allowEmpty: true },
},
},
COMPANY: {
name: "Company",
icon: "ri-store-line",
type: "string",
constraints: {
type: "string",
length: {},
presence: { allowEmpty: true },
},
},
EMAIL: {
name: "Email",
icon: "ri-mail-line",
type: "string",
constraints: {
type: "string",
length: {},
presence: { allowEmpty: true },
},
},
PHONE_NUMBER: {
name: "Phone No.",
icon: "ri-phone-line",
type: "number",
constraints: {
type: "number",
presence: { allowEmpty: true },
numericality: {},
},
},
VALUE: {
name: "Value",
icon: "ri-number-5",
type: "number",
constraints: {
type: "number",
presence: { allowEmpty: true },
numericality: {},
},
},
ACTIVE: {
name: "Active",
icon: "ri-toggle-line",
type: "boolean",
constraints: {
type: "boolean",
presence: { allowEmpty: true },
},
},
URL: {
name: "URL",
icon: "ri-link",
type: "string",
constraints: {
type: "string",
length: {},
presence: { allowEmpty: true },
},
},
IMAGE: {
name: "Image URL",
icon: "ri-image-line",
type: "string",
constraints: {
type: "string",
length: {},
presence: { allowEmpty: true },
},
},
// PRIORITY: {
// name: "Options",
// icon: "ri-list-check-2",
// type: "options",
// constraints: {
// type: "string",
// presence: { allowEmpty: true },
// inclusion: ["low", "medium", "high"],
// },
// },
END_DATE: {
name: "End Date",
icon: "ri-calendar-event-fill",
type: "string",
constraints: {
type: "string",
length: {},
presence: { allowEmpty: true },
},
},
// AVATAR: {
// name: "Avatar",
// icon: "ri-image-line",
// type: "image",
// constraints: {
// type: "string",
// presence: { allowEmpty: true },
// },
// },
// PDF: {
// name: "PDF",
// icon: "ri-file-line",
// type: "file",
// constraints: {
// type: "string",
// presence: { allowEmpty: true },
// },
// },
}