diff --git a/app/components/app/equipment/entry-form.vue b/app/components/app/equipment/entry-form.vue index 759f011d..bb2b0545 100644 --- a/app/components/app/equipment/entry-form.vue +++ b/app/components/app/equipment/entry-form.vue @@ -3,30 +3,36 @@ import type z from 'zod' import type { MaterialFormData } from '~/schemas/material' // helpers -import { toTypedSchema } from '@vee-validate/zod' import { useForm } from 'vee-validate' +import { toTypedSchema } from '@vee-validate/zod' // components +import Block from '~/components/pub/custom-ui/doc-entry/block.vue' +import Cell from '~/components/pub/custom-ui/doc-entry/cell.vue' +import Field from '~/components/pub/custom-ui/doc-entry/field.vue' +import Label from '~/components/pub/custom-ui/doc-entry/label.vue' interface Props { schema: z.ZodSchema uoms: any[] - items: any[] + values: any + isLoading?: boolean + isReadonly?: boolean } -const isLoading = ref(false) const props = defineProps() +const isLoading = props.isLoading !== undefined ? props.isLoading : false +const isReadonly = props.isReadonly !== undefined ? props.isReadonly : false const emit = defineEmits<{ submit: [values: MaterialFormData, resetForm: () => void] cancel: [resetForm: () => void] }>() -const { handleSubmit, defineField, errors } = useForm({ +const { defineField, errors, meta } = useForm({ validationSchema: toTypedSchema(props.schema), initialValues: { code: '', name: '', uom_code: '', - item_id: '', stock: 0, } as Partial, }) @@ -34,113 +40,83 @@ const { handleSubmit, defineField, errors } = useForm({ const [code, codeAttrs] = defineField('code') const [name, nameAttrs] = defineField('name') const [uom, uomAttrs] = defineField('uom_code') -const [item, itemAttrs] = defineField('item_id') const [stock, stockAttrs] = defineField('stock') +// Fill fields from props.values if provided +if (props.values) { + if (props.values.code !== undefined) code.value = props.values.code + if (props.values.name !== undefined) name.value = props.values.name + if (props.values.uom_code !== undefined) uom.value = props.values.uom_code + if (props.values.stock !== undefined) stock.value = props.values.stock +} + const resetForm = () => { code.value = '' name.value = '' uom.value = '' - item.value = '' stock.value = 0 } -// Form submission handler -function onSubmitForm(values: any) { +function onSubmitForm() { const formData: MaterialFormData = { - name: values.name || '', - code: values.code || '', - uom_code: values.uom_code || '', - item_id: values.item_id || '', - stock: values.stock || 0, + name: name.value || '', + code: code.value || '', + uom_code: uom.value || '', + stock: stock.value || 0, } emit('submit', formData, resetForm) } -// Form cancel handler function onCancelForm() { emit('cancel', resetForm) }