@uplink-protocol/form-controller
Version:
Reactive multi-step form controller with dynamic validation and state management
71 lines (70 loc) • 3.24 kB
TypeScript
import { BaseService } from './base.service';
import { ConfigService } from './config.service';
import { FormStep } from '../interfaces/form-step.interface';
/**
* Service for managing multi-step form navigation
*/
export declare class StepperService extends BaseService<number> {
private configService;
constructor(initialStepIndex: number, configService: ConfigService);
/**
* Navigate to the next step if possible
* @param validateCallback Optional validation callback that determines if navigation is allowed
* @returns New step index or current step if navigation isn't possible
*/
nextStep(validateCallback?: () => boolean): number;
/**
* Validate current step and navigate to next if valid
* @param currentStepId Current step ID for touch marking
* @param markStepTouched Function to mark all fields in step as touched
* @param validateStep Function to validate the current step
* @returns New step index or current step if validation fails
*/ validateAndNext(currentStepId: string, markStepTouched: (stepId: string, touched: boolean) => void, validateStep: (showErrors: boolean) => boolean): number;
/**
* Navigate to the previous step if possible
* @returns New step index or 0 if already at first step
*/
prevStep(): number;
/**
* Go to a specific step by index
* @param stepIndex Target step index
* @returns True if navigation was successful, false otherwise
*/
goToStep(stepIndex: number): boolean;
/**
* Check if currently on the first step
* @returns True if on first step
*/
get isFirstStep(): boolean;
/**
* Check if currently on the last step
* @returns True if on last step
*/
get isLastStep(): boolean;
/**
* Validate current step and navigate to next if valid
* Also updates bindings to ensure immediate access to current values
*
* @param currentStep The current step object
* @param markFieldsTouched Function to mark fields as touched
* @param validateCurrentStep Function to validate the current step
* @param updateBindings Function to update bindings after navigation
* @returns New step index or current step if navigation fails
*/
nextStepWithValidation(currentStep: FormStep, markFieldsTouched: (stepId: string, touched: boolean) => void, validateCurrentStep: (showErrors: boolean) => boolean, updateBindings: (newIndex: number, step: FormStep | null) => void): number;
/**
* Enhanced version of prevStep that also updates bindings
*
* @param updateBindings Function to update bindings after navigation
* @returns New step index or current index if navigation fails
*/
prevStepWithBindings(updateBindings: (newIndex: number, step: FormStep | null) => void): number;
/**
* Enhanced version of goToStep that also updates bindings
*
* @param stepIndex Target step index
* @param updateBindings Function to update bindings after navigation
* @returns True if navigation succeeded, false otherwise
*/
goToStepWithBindings(stepIndex: number, updateBindings: (newIndex: number, step: FormStep | null) => void): boolean;
}