UNPKG

@anushase/json-form-builder

Version:

A dynamic JSON form builder with multi-language support, validation, and responsive design

131 lines (130 loc) 3.35 kB
export interface KeyValuePair { [key: string]: string; } export interface Label extends KeyValuePair { } export interface FormField { id: string; controlType: "textbox" | "password" | "date" | "dropdown" | "checkbox" | "phone" | "photo"; type?: "string" | "simpleType"; labelName: Label; required?: boolean; validators?: Validator[]; alignmentGroup?: string; cssClasses?: string[]; placeholder?: Label; disabled?: boolean; info?: Label; capsLockCheck?: boolean; prefix?: string[]; acceptedFileTypes?: string[]; format?: string; } export interface AllowedValues { [key: string]: { [key: string]: Label; } | string; } export interface SubmitButtonConfig { label: string; action: (data: FormData) => void; } export interface LanguageConfig { currentLanguage?: string; defaultLanguage?: string; showLanguageSwitcher?: boolean; languageSwitcherPosition?: "top" | "bottom"; availableLanguages?: string[]; rtlLanguages?: string[]; } export interface ReCaptchaConfig { siteKey: string; enabled?: boolean; language?: string; } export interface AdditionalSchema { [id: string]: { label: Label; placeholder: Label; }; } export interface AdditionalConfig { submitButton: SubmitButtonConfig; language?: LanguageConfig; recaptcha?: ReCaptchaConfig; additionalSchema?: AdditionalSchema; } export interface Errors { [key: string]: KeyValuePair; } export interface FormConfig { schema: FormField[]; language: LanguageSettings; allowedValues?: AllowedValues; errors?: Errors; maxUploadFileSize?: number; i18nValues?: { errors?: Errors; labels?: { [id: string]: Label; }; placeholders?: { [id: string]: Label; }; }; } export interface FileUploadData { value: string | Blob; docType: string; format: string; refId: string; } export type FormValue = string | boolean | KeyValuePair | KeyValuePair[] | File | FileUploadData | undefined; export interface FormData { [key: string]: FormValue; } export interface LanguageSettings { mandatory: string[]; langCodeMap: KeyValuePair; optional?: string[]; } export interface Validator { regex?: RegExp | string; error?: KeyValuePair; langCode?: string; } export interface FormState { schema: FormField[]; allowedValues: AllowedValues; mandatoryLanguages: string[]; optionalLanguages: string[]; container: HTMLElement; formData: FormData; formElements: { [key: string]: HTMLElement | { [key: string]: HTMLElement; }; }; submitLabel: string; submitAction: (data: FormData) => void; currentLanguage: string; defaultLanguage: string; showLanguageSwitcher: boolean; languageSwitcherPosition: "top" | "bottom"; availableLanguages: string[]; rtlLanguages: string[]; isRTL: boolean; recaptcha?: ReCaptchaConfig; fallbackErrors: Errors; lastErrors?: Record<string, "required" | number | null>; languageMap: KeyValuePair; additionalSchema?: AdditionalSchema; isSubmitting: boolean; maxUploadFileSize: number; labels: { [id: string]: Label; }; placeholders: { [id: string]: Label; }; }