mirror of
https://github.com/directus/directus.git
synced 2026-02-15 02:04:58 -05:00
* added default values when validating items * abstracted default value parsing to its own util * Added a basic test * updated tests * fixed import * implementing the same fix for conditions on the drawer-item
22 lines
664 B
TypeScript
22 lines
664 B
TypeScript
import { Field } from '@directus/shared/types';
|
|
import { Ref, unref, computed, ComputedRef } from 'vue';
|
|
|
|
export function getDefaultValuesFromFields(fields: Field[] | Ref<Field[]>): ComputedRef<Record<string, any>> {
|
|
return computed(() => {
|
|
return unref(fields).reduce(function (acc, field) {
|
|
if (
|
|
field.schema?.default_value !== undefined &&
|
|
// Ignore autoincremented integer PK field
|
|
!(
|
|
field.schema.is_primary_key &&
|
|
field.schema.data_type === 'integer' &&
|
|
typeof field.schema.default_value === 'string'
|
|
)
|
|
) {
|
|
acc[field.field] = field.schema.default_value;
|
|
}
|
|
return acc;
|
|
}, {} as Record<string, any>);
|
|
});
|
|
}
|