diff --git a/app/src/composables/use-collection/use-collection.ts b/app/src/composables/use-collection/use-collection.ts index d14374bf1c..e9efcc3143 100644 --- a/app/src/composables/use-collection/use-collection.ts +++ b/app/src/composables/use-collection/use-collection.ts @@ -16,6 +16,20 @@ export function useCollection(collectionKey: string | Ref) { return fieldsStore.getFieldsForCollection(collection.value); }); + const defaults = computed(() => { + if (!fields.value) return {}; + + const defaults: Record = {}; + + for (const field of fields.value) { + if (field.schema?.default_value) { + defaults[field.field] = field.schema.default_value; + } + } + + return defaults; + }); + const primaryKeyField = computed(() => { // Every collection has a primary key; rules of the land // eslint-disable-next-line @typescript-eslint/no-non-null-assertion @@ -32,5 +46,5 @@ export function useCollection(collectionKey: string | Ref) { return info.value?.meta?.sort_field || null; }); - return { info, fields, primaryKeyField, userCreatedField, sortField }; + return { info, fields, defaults, primaryKeyField, userCreatedField, sortField }; } diff --git a/app/src/composables/use-item/use-item.ts b/app/src/composables/use-item/use-item.ts index a1f0466456..d0850b9d13 100644 --- a/app/src/composables/use-item/use-item.ts +++ b/app/src/composables/use-item/use-item.ts @@ -16,7 +16,7 @@ export function useItem(collection: Ref, primaryKey: Ref>({}); const isNew = computed(() => primaryKey.value === '+'); const isBatch = computed(() => typeof primaryKey.value === 'string' && primaryKey.value.includes(',')); const isSingle = computed(() => !!collectionInfo.value?.meta?.singleton); diff --git a/app/src/modules/collections/routes/item.vue b/app/src/modules/collections/routes/item.vue index df71a117f8..2b8cbdf319 100644 --- a/app/src/modules/collections/routes/item.vue +++ b/app/src/modules/collections/routes/item.vue @@ -134,7 +134,7 @@ rounded icon :loading="saving" - :disabled="saveAllowed === false || hasEdits === false" + :disabled="isSavable === false" v-tooltip.bottom="saveAllowed ? $t('save') : $t('not_allowed')" @click="saveAndQuit" > @@ -143,7 +143,7 @@