@uplink-protocol/form-controller
Version:
Reactive multi-step form controller with dynamic validation and state management
50 lines (49 loc) • 2.6 kB
TypeScript
import { FormConfig } from "./interfaces/form-config.interface";
import { FormStep } from "./interfaces/form-step.interface";
import { DynamicValidator } from "./utils/validator-registry";
/**
* DynamicFormStepperController - A controller for multi-step forms with dynamic configuration
* @param config - The form configuration with steps and field definitions
* @returns A controller instance with bindings and methods for form state management
*/
export declare const FormController: (config: FormConfig) => {
bindings: {
config: import("@uplink-protocol/core").Binding<FormConfig>;
currentStepIndex: import("@uplink-protocol/core").Binding<number>;
currentStep: import("@uplink-protocol/core").Binding<FormStep>;
formData: import("@uplink-protocol/core").Binding<Record<string, Record<string, any>>>;
stepsValidity: import("@uplink-protocol/core").Binding<Record<string, boolean>>;
fieldErrors: import("@uplink-protocol/core").Binding<{}>;
totalSteps: import("@uplink-protocol/core").Binding<number>;
isLastStep: import("@uplink-protocol/core").Binding<boolean>;
isFirstStep: import("@uplink-protocol/core").Binding<boolean>;
isFormValid: import("@uplink-protocol/core").Binding<boolean>;
};
methods: {
nextStep: () => number;
prevStep: () => number;
goToStep: (stepIndex: number) => boolean;
updateField: (stepId: string, fieldId: string, value: any) => void;
validateField: (stepId: string, fieldId: string, value?: any, showErrors?: boolean) => boolean;
validateStep: (stepId: string, showErrors?: boolean) => boolean;
validateCurrentStep: (showErrors?: boolean) => boolean;
validateCurrentStepWithTouchedErrors: () => boolean;
validateStepWithTouchedErrors: (stepId: string) => boolean;
validateForm: (showErrors?: boolean) => boolean;
submitForm: () => {
success: boolean;
data?: any;
errors?: any;
};
resetForm: () => void;
updateConfig: (newConfig: FormConfig) => void;
getStepData: (stepId: string) => Record<string, any>;
getAllData: () => Record<string, Record<string, any>>;
getFlatData: () => Record<string, any>;
addStep: (step: FormStep, index?: number) => number;
removeStep: (stepId: string) => boolean;
registerValidator: (name: string, validatorFn: DynamicValidator) => void;
unregisterValidator: (name: string) => boolean;
getAvailableValidators: () => string[];
};
};