Enable default values on options columns with validation and fix default values being available on primary display columns
This commit is contained in:
parent
2d1662c0c7
commit
fd21503f3e
|
@ -136,9 +136,8 @@
|
||||||
}
|
}
|
||||||
$: initialiseField(field, savingColumn)
|
$: initialiseField(field, savingColumn)
|
||||||
$: checkConstraints(editableColumn)
|
$: checkConstraints(editableColumn)
|
||||||
$: required = hasDefault
|
$: required =
|
||||||
? false
|
primaryDisplay || (!hasDefault && !!editableColumn?.constraints?.presence)
|
||||||
: !!editableColumn?.constraints?.presence || primaryDisplay
|
|
||||||
$: uneditable =
|
$: uneditable =
|
||||||
$tables.selected?._id === TableNames.USERS &&
|
$tables.selected?._id === TableNames.USERS &&
|
||||||
UNEDITABLE_USER_FIELDS.includes(editableColumn.name)
|
UNEDITABLE_USER_FIELDS.includes(editableColumn.name)
|
||||||
|
@ -168,7 +167,9 @@
|
||||||
$: canBeDisplay =
|
$: canBeDisplay =
|
||||||
canBeDisplayColumn(editableColumn.type) && !editableColumn.autocolumn
|
canBeDisplayColumn(editableColumn.type) && !editableColumn.autocolumn
|
||||||
$: canHaveDefault =
|
$: canHaveDefault =
|
||||||
isEnabled("DEFAULT_VALUES") && canHaveDefaultColumn(editableColumn.type)
|
!required &&
|
||||||
|
isEnabled("DEFAULT_VALUES") &&
|
||||||
|
canHaveDefaultColumn(editableColumn.type)
|
||||||
$: canBeRequired =
|
$: canBeRequired =
|
||||||
editableColumn?.type !== LINK_TYPE &&
|
editableColumn?.type !== LINK_TYPE &&
|
||||||
!uneditable &&
|
!uneditable &&
|
||||||
|
@ -187,11 +188,11 @@
|
||||||
(originalName &&
|
(originalName &&
|
||||||
SWITCHABLE_TYPES[field.type] &&
|
SWITCHABLE_TYPES[field.type] &&
|
||||||
!editableColumn?.autocolumn)
|
!editableColumn?.autocolumn)
|
||||||
|
|
||||||
$: allowedTypes = getAllowedTypes(datasource).map(t => ({
|
$: allowedTypes = getAllowedTypes(datasource).map(t => ({
|
||||||
fieldId: makeFieldId(t.type, t.subtype),
|
fieldId: makeFieldId(t.type, t.subtype),
|
||||||
...t,
|
...t,
|
||||||
}))
|
}))
|
||||||
|
$: bindings = getBindings({ table })
|
||||||
|
|
||||||
const fieldDefinitions = Object.values(FIELDS).reduce(
|
const fieldDefinitions = Object.values(FIELDS).reduce(
|
||||||
// Storing the fields by complex field id
|
// Storing the fields by complex field id
|
||||||
|
@ -281,6 +282,20 @@
|
||||||
delete saveColumn.fieldName
|
delete saveColumn.fieldName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure the field is not required if we have a default value
|
||||||
|
if (saveColumn.default) {
|
||||||
|
saveColumn.constraints.presence = false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete default value for options fields if the option is no longer available
|
||||||
|
if (
|
||||||
|
saveColumn.type === FieldType.OPTIONS &&
|
||||||
|
saveColumn.default &&
|
||||||
|
!saveColumn.constraints.inclusion?.includes(saveColumn.default)
|
||||||
|
) {
|
||||||
|
delete saveColumn.default
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await tables.saveField({
|
await tables.saveField({
|
||||||
originalName,
|
originalName,
|
||||||
|
@ -727,7 +742,7 @@
|
||||||
formula: e.detail,
|
formula: e.detail,
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
bindings={getBindings({ table })}
|
{bindings}
|
||||||
allowJS
|
allowJS
|
||||||
context={rowGoldenSample}
|
context={rowGoldenSample}
|
||||||
/>
|
/>
|
||||||
|
@ -766,27 +781,27 @@
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if canHaveDefault}
|
{#if canHaveDefault}
|
||||||
<div>
|
{#if editableColumn.type === FieldType.OPTIONS}
|
||||||
|
<Select
|
||||||
|
options={editableColumn.constraints?.inclusion || []}
|
||||||
|
label="Default value"
|
||||||
|
value={editableColumn.default}
|
||||||
|
on:change={e => (editableColumn.default = e.detail)}
|
||||||
|
placeholder="None"
|
||||||
|
/>
|
||||||
|
{:else}
|
||||||
<ModalBindableInput
|
<ModalBindableInput
|
||||||
panel={ServerBindingPanel}
|
panel={ServerBindingPanel}
|
||||||
title="Default"
|
title="Default value"
|
||||||
label="Default"
|
label="Default value"
|
||||||
|
placeholder="None"
|
||||||
value={editableColumn.default}
|
value={editableColumn.default}
|
||||||
on:change={e => {
|
on:change={e => (editableColumn.default = e.detail)}
|
||||||
editableColumn = {
|
{bindings}
|
||||||
...editableColumn,
|
|
||||||
default: e.detail,
|
|
||||||
}
|
|
||||||
|
|
||||||
if (e.detail) {
|
|
||||||
setRequired(false)
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
bindings={getBindings({ table })}
|
|
||||||
allowJS
|
allowJS
|
||||||
context={rowGoldenSample}
|
context={rowGoldenSample}
|
||||||
/>
|
/>
|
||||||
</div>
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
</Layout>
|
</Layout>
|
||||||
|
|
||||||
|
|
|
@ -53,8 +53,8 @@ const allowDefaultColumnByType: Record<FieldType, boolean> = {
|
||||||
[FieldType.DATETIME]: true,
|
[FieldType.DATETIME]: true,
|
||||||
[FieldType.LONGFORM]: true,
|
[FieldType.LONGFORM]: true,
|
||||||
[FieldType.STRING]: true,
|
[FieldType.STRING]: true,
|
||||||
|
[FieldType.OPTIONS]: true,
|
||||||
|
|
||||||
[FieldType.OPTIONS]: false,
|
|
||||||
[FieldType.AUTO]: false,
|
[FieldType.AUTO]: false,
|
||||||
[FieldType.INTERNAL]: false,
|
[FieldType.INTERNAL]: false,
|
||||||
[FieldType.BARCODEQR]: false,
|
[FieldType.BARCODEQR]: false,
|
||||||
|
|
Loading…
Reference in New Issue