@code-gorilla-au/vue-forms
Version:
form authoring light weight framework
73 lines (72 loc) • 1.99 kB
TypeScript
import { ComputedRef } from 'vue';
import { DispatchEventTopic } from '../lib/dispatch';
export interface VFormDataList {
__id: string;
[key: string]: string | object | number;
}
export interface VFormData {
[key: string]: string | number | VFormDataList[];
}
export interface VFormValidations {
[key: string]: string | undefined;
}
export interface VFormNode {
id: string;
name: string;
type: string;
required: boolean;
readonly: boolean;
disabled: boolean;
focused: boolean;
dirty: boolean;
valid: boolean;
validationMessage: string;
value: string | boolean | object;
namespace?: string;
}
export interface VFormNodes {
[key: string]: VFormNode;
}
export declare const EVENT_UPDATE_DATA: DispatchEventTopic;
export interface VFormContextApi {
/**
* read only version of form nodes
*/
readonly nodes: VFormNodes;
/**
* read only version of form data
*/
readonly data: VFormData;
/**
* read only version of form validations
*/
readonly validations: VFormValidations;
/**
* Flag if the form is valid for submission
*/
formValid: ComputedRef<boolean>;
/**
* register an input node with the form context
* @param node form node
*/
registerNode(node: VFormNode): void;
/**
* get input node by id
* @param id unique id
*/
getNode(id: string): VFormNode;
/**
* dispatch event with form node
* @param event event
* @param node input node
*/
dispatch(event: DispatchEventTopic, node: VFormNode): Promise<void>;
/**
* validate input based on default rules engine
* @param inputValue input value
* @param expression validation rules
*/
validate(inputValue: string, expression: string): string | undefined;
}
export declare function createFormContext(initFormData?: {}): VFormContextApi;
export declare function useFormContext(): VFormContextApi | undefined;