Primary display column is always required

This commit is contained in:
Michael Shanks 2020-10-16 21:50:58 +01:00
parent 3f53e2958b
commit 143177a0d5
1 changed files with 11 additions and 1 deletions

View File

@ -40,7 +40,7 @@
$: tableOptions = $backendUiStore.tables.filter( $: tableOptions = $backendUiStore.tables.filter(
table => table._id !== $backendUiStore.draftTable._id table => table._id !== $backendUiStore.draftTable._id
) )
$: required = !!field?.constraints?.presence $: required = !!field?.constraints?.presence || primaryDisplay
async function saveColumn() { async function saveColumn() {
backendUiStore.update(state => { backendUiStore.update(state => {
@ -67,6 +67,14 @@
field.constraints.presence = req ? { allowEmpty: false } : false field.constraints.presence = req ? { allowEmpty: false } : false
required = req required = req
} }
function onChangePrimaryDisplay(e) {
const isPrimary = e.target.checked
// primary display is always required
if (isPrimary) {
field.constraints.presence = { allowEmpty: false }
}
}
</script> </script>
<div class="actions"> <div class="actions">
@ -88,6 +96,7 @@
<Toggle <Toggle
checked={required} checked={required}
on:change={onChangeRequired} on:change={onChangeRequired}
disabled={primaryDisplay}
thin thin
text="Required" /> text="Required" />
{/if} {/if}
@ -95,6 +104,7 @@
{#if field.type !== 'link'} {#if field.type !== 'link'}
<Toggle <Toggle
bind:checked={primaryDisplay} bind:checked={primaryDisplay}
on:change={onChangePrimaryDisplay}
thin thin
text="Use as table display column" /> text="Use as table display column" />
{/if} {/if}