diff --git a/packages/forms/src/form/Form.d.ts b/packages/forms/src/form/Form.d.ts index 9813b2444..0eedcf220 100644 --- a/packages/forms/src/form/Form.d.ts +++ b/packages/forms/src/form/Form.d.ts @@ -11,6 +11,7 @@ import type { DefineComponent, DesignToken, EmitFn, PassThrough } from '@primevu import type { ComponentHooks } from '@primevue/core/basecomponent'; import { VNode } from 'vue'; import type { PassThroughOptions } from '../types'; +import { useFormFieldState } from '../useform'; export declare type FormPassThroughOptionType = FormPassThroughAttributes | ((options: FormPassThroughMethodOptions) => FormPassThroughAttributes | string) | string | null | undefined; @@ -267,6 +268,48 @@ export interface FormEmitsOptions { export declare type FormEmits = EmitFn; +export interface FormFieldState extends useFormFieldState {} + +export interface FormInstance { + /** + * Set the value of a form field. + * @param field field name + * @param value field value + */ + setFieldValue: (field: string, value: any) => void; + /** + * Validates the form or a specific field. + * @param field + * @returns + */ + validate: (field?: string | string[]) => Promise<{ + values?: any; + errors: any; + }>; + /** + * Sets the values of the form fields. + * @param values + */ + setValues: (values: Record) => void; + /** + * Resets the entire form state, clearing values and validation statuses. + */ + reset: () => void; + /** + * Submits the form. + * @returns + */ + submit: () => void; + /** + * Whether the form is valid. + */ + valid: boolean; + /** + * The state of each form field, with the field name as the key and its state as the value. + */ + states: Record; +} + /** * **PrimeVue - Form** * diff --git a/packages/forms/src/form/Form.vue b/packages/forms/src/form/Form.vue index e24d2222c..987543838 100644 --- a/packages/forms/src/form/Form.vue +++ b/packages/forms/src/form/Form.vue @@ -1,5 +1,5 @@ @@ -7,6 +7,7 @@