shadcn-zod-formkit 1.26.0 → 1.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -83,14 +83,15 @@ declare enum InputTypes {
83
83
  }
84
84
  declare const inputFieldComp: InputTypes[];
85
85
 
86
- declare const flattenFields: <T extends Record<string, any>>(fields: FieldConfig<T>[]) => FieldProps<T>[];
86
+ declare const flattenFields: <T extends Record<string, any>>(fields: FieldConfig<T>[], onAnyFieldChange?: (data: any) => void) => FieldProps<T>[];
87
87
  type FieldConfig<T, RT = Record<string, any>> = FieldProps<T, RT> | FieldConfig<T, RT>[];
88
88
  interface FieldProps<T = Record<string, any>, RT = Record<string, any>> {
89
89
  name: keyof T;
90
90
  label: string;
91
+ form?: UseFormReturn<any>;
91
92
  isRemovebleOption?: boolean;
92
93
  withDuplicatTag?: boolean;
93
- onChange?: (...event: any[]) => void;
94
+ onChange?: (event: any[], formValues?: Record<string, any>) => void;
94
95
  tabLabelField?: string;
95
96
  childrenPosition?: 'up' | 'down';
96
97
  children?: ReactNode | ((item: any, index: number) => ReactNode);
@@ -101,6 +102,7 @@ interface FieldProps<T = Record<string, any>, RT = Record<string, any>> {
101
102
  maxItems?: number;
102
103
  currencyFormat?: Intl.NumberFormatOptions;
103
104
  mask?: string | RegExp;
105
+ onAnyFieldChange?: (data: Record<string, any>) => void;
104
106
  wrapInCard?: boolean;
105
107
  placeHolder?: string;
106
108
  description?: string;
@@ -207,6 +209,7 @@ declare const entitiesToInputOption: (data: any[], optionValue?: string, grouped
207
209
  declare const entityToGroupedOption: (entitiy: any, name?: string) => GroupedOption;
208
210
  declare const entitiesToGroupedOption: (data: any[], optionValue?: string) => GroupedOption[];
209
211
  declare const handleOnChage: (event: any[] | any, input: FieldProps, field?: ControllerRenderProps<FieldValues, string>) => void;
212
+ declare const isValidField: (input: FieldProps, form: UseFormReturn, defaultValue?: any) => boolean;
210
213
 
211
214
  type alertPositionType = 'up' | 'down';
212
215
  interface FormResp<T> {
@@ -221,6 +224,7 @@ interface Props$h<T extends Record<string, any>> {
221
224
  readOnly?: boolean;
222
225
  fields: FieldConfig<T>[];
223
226
  record?: Partial<T>;
227
+ onAnyFieldChange?: (data: Record<string, any>) => void;
224
228
  onSubmit?: (resp: FormResp<T>) => void;
225
229
  onClick?: (resp: FormResp<T>) => void;
226
230
  extraValidations?: ((schema: ZodObject<any>) => ZodObject<any>)[];
@@ -237,7 +241,7 @@ interface Props$h<T extends Record<string, any>> {
237
241
  childrenHeader?: ReactNode;
238
242
  listBtnConfig?: BtnConfig[];
239
243
  }
240
- declare const DynamicForm: <T extends Record<string, any>>({ formTitle, formSubTitle, fields, readOnly, record, onSubmit, onClick, extraValidations, children, childrenHeader, showIcon, showFormHeader, withErrorsAlert, errorAlertPosition, withCard, submitBtnClass, listBtnConfig, submitBtnLabel, submitBtnLabelSubmiting, withFormWrapper, btnGroupDirection, withSubmitBtn }: Props$h<T>) => react_jsx_runtime.JSX.Element;
244
+ declare const DynamicForm: <T extends Record<string, any>>({ formTitle, formSubTitle, fields, readOnly, record, onAnyFieldChange, onSubmit, onClick, extraValidations, children, childrenHeader, showIcon, showFormHeader, withErrorsAlert, errorAlertPosition, withCard, submitBtnClass, listBtnConfig, submitBtnLabel, submitBtnLabelSubmiting, withFormWrapper, btnGroupDirection, withSubmitBtn }: Props$h<T>) => react_jsx_runtime.JSX.Element;
241
245
 
242
246
  declare const DynamicFormExample: () => react_jsx_runtime.JSX.Element;
243
247
  declare const mockFields: Array<FieldProps | FieldProps[]>;
@@ -734,4 +738,4 @@ declare function TooltipContent({ className, sideOffset, children, ...props }: R
734
738
 
735
739
  declare function cn(...inputs: ClassValue[]): string;
736
740
 
737
- export { Accordion, AccordionContent, AccordionGroupedSwitchInput, AccordionGroupedSwitches, AccordionItem, AccordionTrigger, Alert, AlertDescription, AlertTitle, Badge, BaseInput, type BtnConfig, Button, ButtonGroup, ButtonGroupInput, ButtonGroupSeparator, ButtonGroupText, Calendar, CalendarDayButton, Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, CheckListInput, Checkbox, CheckboxInput, ColorCnInput, type ColorCompProps, ColorInput, ComboboxInput, Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, CurrencyInput, CustomAlert, DateInput, DateTimeInput, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DynamicForm, DynamicFormExample, Field, FieldButtonGroup, type FieldConfig, FieldContent, FieldCurrency, FieldDateTimeInput, FieldDescription, FieldError, FieldFileMultiUpload, FieldGroup, FieldKeyValueList, FieldLabel, FieldLegend, type FieldProps, FieldRepeater, FieldSeparator, FieldSet, FieldSimpleCheckList, FieldSlider, FieldStringValueList, FieldTextGroup, FieldTimeInput, FieldTitle, FileInput, FileMultiUploadInput, Form, FormControl, FormDescription, FormErrorsAlert, FormField, FormFieldsGrid, FormItem, FormLabel, FormMessage, type FormResp, GenericFilter, type GroupedOption, GroupedSwitchInput, GroupedSwitches, Input, InputFactory, InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput, InputGroupText, InputGroupTextarea, InputList, InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot, type InputOption, type InputSetup, InputTypes, KeyValueListInput, Label, MultiSelectInput, NumberInput, OTPInput, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, type Props, RadioGroup, RadioGroupInput, RadioGroupItem, RepeaterInput, RepeaterTabsInput, ResizableHandle, ResizablePanel, ResizablePanelGroup, ScrollArea, ScrollBar, Select, SelectContent, SelectGroup, SelectInput, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator, SimpleCheckListInput, Slider, SliderInput, SortableListInput, StringValueListInput, Switch, SwitchInput, Tabs, TabsContent, TabsList, TabsTrigger, TagInput, TextAreaInput, TextInput, TextInputGroup, TextInputType, Textarea, TimeInput, Toaster, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, badgeVariants, buttonGroupVariants, buttonVariants, cn, entitiesToGroupedOption, entitiesToInputOption, entityToGroupedOption, entityToInputOption, flattenFields, getDefaultValues, getDynamicSchema, getFieldLabel, handleOnChage, inputFieldComp, mockFields, useFormField, validationMessages };
741
+ export { Accordion, AccordionContent, AccordionGroupedSwitchInput, AccordionGroupedSwitches, AccordionItem, AccordionTrigger, Alert, AlertDescription, AlertTitle, Badge, BaseInput, type BtnConfig, Button, ButtonGroup, ButtonGroupInput, ButtonGroupSeparator, ButtonGroupText, Calendar, CalendarDayButton, Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, CheckListInput, Checkbox, CheckboxInput, ColorCnInput, type ColorCompProps, ColorInput, ComboboxInput, Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, CurrencyInput, CustomAlert, DateInput, DateTimeInput, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DynamicForm, DynamicFormExample, Field, FieldButtonGroup, type FieldConfig, FieldContent, FieldCurrency, FieldDateTimeInput, FieldDescription, FieldError, FieldFileMultiUpload, FieldGroup, FieldKeyValueList, FieldLabel, FieldLegend, type FieldProps, FieldRepeater, FieldSeparator, FieldSet, FieldSimpleCheckList, FieldSlider, FieldStringValueList, FieldTextGroup, FieldTimeInput, FieldTitle, FileInput, FileMultiUploadInput, Form, FormControl, FormDescription, FormErrorsAlert, FormField, FormFieldsGrid, FormItem, FormLabel, FormMessage, type FormResp, GenericFilter, type GroupedOption, GroupedSwitchInput, GroupedSwitches, Input, InputFactory, InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput, InputGroupText, InputGroupTextarea, InputList, InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot, type InputOption, type InputSetup, InputTypes, KeyValueListInput, Label, MultiSelectInput, NumberInput, OTPInput, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, type Props, RadioGroup, RadioGroupInput, RadioGroupItem, RepeaterInput, RepeaterTabsInput, ResizableHandle, ResizablePanel, ResizablePanelGroup, ScrollArea, ScrollBar, Select, SelectContent, SelectGroup, SelectInput, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator, SimpleCheckListInput, Slider, SliderInput, SortableListInput, StringValueListInput, Switch, SwitchInput, Tabs, TabsContent, TabsList, TabsTrigger, TagInput, TextAreaInput, TextInput, TextInputGroup, TextInputType, Textarea, TimeInput, Toaster, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, badgeVariants, buttonGroupVariants, buttonVariants, cn, entitiesToGroupedOption, entitiesToInputOption, entityToGroupedOption, entityToInputOption, flattenFields, getDefaultValues, getDynamicSchema, getFieldLabel, handleOnChage, inputFieldComp, isValidField, mockFields, useFormField, validationMessages };
package/dist/index.d.ts CHANGED
@@ -83,14 +83,15 @@ declare enum InputTypes {
83
83
  }
84
84
  declare const inputFieldComp: InputTypes[];
85
85
 
86
- declare const flattenFields: <T extends Record<string, any>>(fields: FieldConfig<T>[]) => FieldProps<T>[];
86
+ declare const flattenFields: <T extends Record<string, any>>(fields: FieldConfig<T>[], onAnyFieldChange?: (data: any) => void) => FieldProps<T>[];
87
87
  type FieldConfig<T, RT = Record<string, any>> = FieldProps<T, RT> | FieldConfig<T, RT>[];
88
88
  interface FieldProps<T = Record<string, any>, RT = Record<string, any>> {
89
89
  name: keyof T;
90
90
  label: string;
91
+ form?: UseFormReturn<any>;
91
92
  isRemovebleOption?: boolean;
92
93
  withDuplicatTag?: boolean;
93
- onChange?: (...event: any[]) => void;
94
+ onChange?: (event: any[], formValues?: Record<string, any>) => void;
94
95
  tabLabelField?: string;
95
96
  childrenPosition?: 'up' | 'down';
96
97
  children?: ReactNode | ((item: any, index: number) => ReactNode);
@@ -101,6 +102,7 @@ interface FieldProps<T = Record<string, any>, RT = Record<string, any>> {
101
102
  maxItems?: number;
102
103
  currencyFormat?: Intl.NumberFormatOptions;
103
104
  mask?: string | RegExp;
105
+ onAnyFieldChange?: (data: Record<string, any>) => void;
104
106
  wrapInCard?: boolean;
105
107
  placeHolder?: string;
106
108
  description?: string;
@@ -207,6 +209,7 @@ declare const entitiesToInputOption: (data: any[], optionValue?: string, grouped
207
209
  declare const entityToGroupedOption: (entitiy: any, name?: string) => GroupedOption;
208
210
  declare const entitiesToGroupedOption: (data: any[], optionValue?: string) => GroupedOption[];
209
211
  declare const handleOnChage: (event: any[] | any, input: FieldProps, field?: ControllerRenderProps<FieldValues, string>) => void;
212
+ declare const isValidField: (input: FieldProps, form: UseFormReturn, defaultValue?: any) => boolean;
210
213
 
211
214
  type alertPositionType = 'up' | 'down';
212
215
  interface FormResp<T> {
@@ -221,6 +224,7 @@ interface Props$h<T extends Record<string, any>> {
221
224
  readOnly?: boolean;
222
225
  fields: FieldConfig<T>[];
223
226
  record?: Partial<T>;
227
+ onAnyFieldChange?: (data: Record<string, any>) => void;
224
228
  onSubmit?: (resp: FormResp<T>) => void;
225
229
  onClick?: (resp: FormResp<T>) => void;
226
230
  extraValidations?: ((schema: ZodObject<any>) => ZodObject<any>)[];
@@ -237,7 +241,7 @@ interface Props$h<T extends Record<string, any>> {
237
241
  childrenHeader?: ReactNode;
238
242
  listBtnConfig?: BtnConfig[];
239
243
  }
240
- declare const DynamicForm: <T extends Record<string, any>>({ formTitle, formSubTitle, fields, readOnly, record, onSubmit, onClick, extraValidations, children, childrenHeader, showIcon, showFormHeader, withErrorsAlert, errorAlertPosition, withCard, submitBtnClass, listBtnConfig, submitBtnLabel, submitBtnLabelSubmiting, withFormWrapper, btnGroupDirection, withSubmitBtn }: Props$h<T>) => react_jsx_runtime.JSX.Element;
244
+ declare const DynamicForm: <T extends Record<string, any>>({ formTitle, formSubTitle, fields, readOnly, record, onAnyFieldChange, onSubmit, onClick, extraValidations, children, childrenHeader, showIcon, showFormHeader, withErrorsAlert, errorAlertPosition, withCard, submitBtnClass, listBtnConfig, submitBtnLabel, submitBtnLabelSubmiting, withFormWrapper, btnGroupDirection, withSubmitBtn }: Props$h<T>) => react_jsx_runtime.JSX.Element;
241
245
 
242
246
  declare const DynamicFormExample: () => react_jsx_runtime.JSX.Element;
243
247
  declare const mockFields: Array<FieldProps | FieldProps[]>;
@@ -734,4 +738,4 @@ declare function TooltipContent({ className, sideOffset, children, ...props }: R
734
738
 
735
739
  declare function cn(...inputs: ClassValue[]): string;
736
740
 
737
- export { Accordion, AccordionContent, AccordionGroupedSwitchInput, AccordionGroupedSwitches, AccordionItem, AccordionTrigger, Alert, AlertDescription, AlertTitle, Badge, BaseInput, type BtnConfig, Button, ButtonGroup, ButtonGroupInput, ButtonGroupSeparator, ButtonGroupText, Calendar, CalendarDayButton, Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, CheckListInput, Checkbox, CheckboxInput, ColorCnInput, type ColorCompProps, ColorInput, ComboboxInput, Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, CurrencyInput, CustomAlert, DateInput, DateTimeInput, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DynamicForm, DynamicFormExample, Field, FieldButtonGroup, type FieldConfig, FieldContent, FieldCurrency, FieldDateTimeInput, FieldDescription, FieldError, FieldFileMultiUpload, FieldGroup, FieldKeyValueList, FieldLabel, FieldLegend, type FieldProps, FieldRepeater, FieldSeparator, FieldSet, FieldSimpleCheckList, FieldSlider, FieldStringValueList, FieldTextGroup, FieldTimeInput, FieldTitle, FileInput, FileMultiUploadInput, Form, FormControl, FormDescription, FormErrorsAlert, FormField, FormFieldsGrid, FormItem, FormLabel, FormMessage, type FormResp, GenericFilter, type GroupedOption, GroupedSwitchInput, GroupedSwitches, Input, InputFactory, InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput, InputGroupText, InputGroupTextarea, InputList, InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot, type InputOption, type InputSetup, InputTypes, KeyValueListInput, Label, MultiSelectInput, NumberInput, OTPInput, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, type Props, RadioGroup, RadioGroupInput, RadioGroupItem, RepeaterInput, RepeaterTabsInput, ResizableHandle, ResizablePanel, ResizablePanelGroup, ScrollArea, ScrollBar, Select, SelectContent, SelectGroup, SelectInput, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator, SimpleCheckListInput, Slider, SliderInput, SortableListInput, StringValueListInput, Switch, SwitchInput, Tabs, TabsContent, TabsList, TabsTrigger, TagInput, TextAreaInput, TextInput, TextInputGroup, TextInputType, Textarea, TimeInput, Toaster, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, badgeVariants, buttonGroupVariants, buttonVariants, cn, entitiesToGroupedOption, entitiesToInputOption, entityToGroupedOption, entityToInputOption, flattenFields, getDefaultValues, getDynamicSchema, getFieldLabel, handleOnChage, inputFieldComp, mockFields, useFormField, validationMessages };
741
+ export { Accordion, AccordionContent, AccordionGroupedSwitchInput, AccordionGroupedSwitches, AccordionItem, AccordionTrigger, Alert, AlertDescription, AlertTitle, Badge, BaseInput, type BtnConfig, Button, ButtonGroup, ButtonGroupInput, ButtonGroupSeparator, ButtonGroupText, Calendar, CalendarDayButton, Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, CheckListInput, Checkbox, CheckboxInput, ColorCnInput, type ColorCompProps, ColorInput, ComboboxInput, Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, CurrencyInput, CustomAlert, DateInput, DateTimeInput, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DynamicForm, DynamicFormExample, Field, FieldButtonGroup, type FieldConfig, FieldContent, FieldCurrency, FieldDateTimeInput, FieldDescription, FieldError, FieldFileMultiUpload, FieldGroup, FieldKeyValueList, FieldLabel, FieldLegend, type FieldProps, FieldRepeater, FieldSeparator, FieldSet, FieldSimpleCheckList, FieldSlider, FieldStringValueList, FieldTextGroup, FieldTimeInput, FieldTitle, FileInput, FileMultiUploadInput, Form, FormControl, FormDescription, FormErrorsAlert, FormField, FormFieldsGrid, FormItem, FormLabel, FormMessage, type FormResp, GenericFilter, type GroupedOption, GroupedSwitchInput, GroupedSwitches, Input, InputFactory, InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput, InputGroupText, InputGroupTextarea, InputList, InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot, type InputOption, type InputSetup, InputTypes, KeyValueListInput, Label, MultiSelectInput, NumberInput, OTPInput, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, type Props, RadioGroup, RadioGroupInput, RadioGroupItem, RepeaterInput, RepeaterTabsInput, ResizableHandle, ResizablePanel, ResizablePanelGroup, ScrollArea, ScrollBar, Select, SelectContent, SelectGroup, SelectInput, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator, SimpleCheckListInput, Slider, SliderInput, SortableListInput, StringValueListInput, Switch, SwitchInput, Tabs, TabsContent, TabsList, TabsTrigger, TagInput, TextAreaInput, TextInput, TextInputGroup, TextInputType, Textarea, TimeInput, Toaster, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, badgeVariants, buttonGroupVariants, buttonVariants, cn, entitiesToGroupedOption, entitiesToInputOption, entityToGroupedOption, entityToInputOption, flattenFields, getDefaultValues, getDynamicSchema, getFieldLabel, handleOnChage, inputFieldComp, isValidField, mockFields, useFormField, validationMessages };
package/dist/index.mjs CHANGED
@@ -15,6 +15,7 @@ import * as PopoverPrimitive from '@radix-ui/react-popover';
15
15
  import 'react-color-palette/css';
16
16
  import * as DialogPrimitive from '@radix-ui/react-dialog';
17
17
  import * as LabelPrimitive from '@radix-ui/react-label';
18
+ import { Label as Label$1 } from '@radix-ui/react-label';
18
19
  import * as SeparatorPrimitive from '@radix-ui/react-separator';
19
20
  import { OTPInput, OTPInputContext } from 'input-otp';
20
21
  import * as RadioGroupPrimitive from '@radix-ui/react-radio-group';
@@ -195,13 +196,23 @@ var entitiesToGroupedOption = (data, optionValue = "name") => {
195
196
  return entities;
196
197
  };
197
198
  var handleOnChage = (event, input, field) => {
198
- console.log("\u{1F680} ~ handleOnChage ~ event:", event);
199
199
  if (event) field?.onChange(event);
200
- input.onChange?.(event);
200
+ const data = input.form?.getValues();
201
+ input.onChange?.(event, data);
202
+ if (input.onAnyFieldChange) input.onAnyFieldChange?.(data);
203
+ };
204
+ var isValidField = (input, form, defaultValue) => {
205
+ const value = defaultValue ?? form.getValues(input.name);
206
+ const fieldState = form.getFieldState(input.name);
207
+ if (input.zodType) {
208
+ const result = input.zodType.safeParse(value);
209
+ return result.success;
210
+ }
211
+ return !fieldState.error && value !== void 0 && value !== "";
201
212
  };
202
213
 
203
214
  // src/components/custom/form/inputs/base/definitions.ts
204
- var flattenFields = (fields) => {
215
+ var flattenFields = (fields, onAnyFieldChange) => {
205
216
  const result = [];
206
217
  for (const field of fields) {
207
218
  if (Array.isArray(field)) {
@@ -209,6 +220,7 @@ var flattenFields = (fields) => {
209
220
  } else if (field.fields) {
210
221
  result.push(...flattenFields(field.fields));
211
222
  } else {
223
+ if (onAnyFieldChange) field.onAnyFieldChange = (data) => onAnyFieldChange(data);
212
224
  result.push(field);
213
225
  }
214
226
  }
@@ -4166,60 +4178,82 @@ function cleanEscapedString(input) {
4166
4178
  var DateInput = class extends BaseInput {
4167
4179
  render() {
4168
4180
  const { input, form, isSubmitting } = this;
4169
- const formField = /* @__PURE__ */ jsx(
4170
- FormField,
4171
- {
4172
- control: form.control,
4173
- name: input.name,
4174
- render: ({ field }) => {
4175
- const [date, setDate] = React3.useState(
4176
- field.value ? new Date(field.value) : void 0
4177
- );
4178
- React3.useEffect(() => {
4179
- if (field.value && !date) {
4180
- setDate(new Date(field.value));
4181
- }
4182
- }, [field.value]);
4183
- const handleSelect = (selectedDate) => {
4184
- setDate(selectedDate);
4185
- handleOnChage(selectedDate, input, field);
4186
- };
4187
- return /* @__PURE__ */ jsxs(FormItem, { children: [
4188
- /* @__PURE__ */ jsx(FormLabel, { children: /* @__PURE__ */ jsx("b", { children: input.label }) }),
4189
- /* @__PURE__ */ jsxs(Popover, { children: [
4190
- /* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsxs(
4191
- Button,
4192
- {
4193
- variant: "outline",
4194
- className: cn(
4195
- "w-full justify-start text-left font-normal",
4196
- !date && "text-muted-foreground"
4197
- ),
4198
- children: [
4181
+ return /* @__PURE__ */ jsx(FieldTimeInput, { input, form, isSubmitting });
4182
+ }
4183
+ };
4184
+ var FieldTimeInput = ({ form, input, isSubmitting }) => {
4185
+ const [isValid2, setIsValid] = useState(isValidField(input, form));
4186
+ const groupConfig = input.inputGroupConfig;
4187
+ const autoValidate = groupConfig?.autoValidIcons ?? input.zodType ? true : false;
4188
+ const iconValidState = /* @__PURE__ */ jsx(CircleCheck, { style: { color: "#00bf3e" } });
4189
+ const iconInvalidState = /* @__PURE__ */ jsx(CircleX, { style: { color: "#ff8080" } });
4190
+ const iconLoadingState = /* @__PURE__ */ jsx(Loader2, { className: "animate-spin", style: { color: "#1e90ff" } });
4191
+ const iconsRight = groupConfig?.iconsRight ?? [];
4192
+ groupConfig?.iconsLeft ?? [];
4193
+ groupConfig?.textLeft;
4194
+ const textRight = groupConfig?.textRight;
4195
+ const formField = /* @__PURE__ */ jsx(
4196
+ FormField,
4197
+ {
4198
+ control: form.control,
4199
+ name: input.name,
4200
+ render: ({ field }) => {
4201
+ setIsValid(isValidField(input, form));
4202
+ const [date, setDate] = React3.useState(
4203
+ field.value ? new Date(field.value) : void 0
4204
+ );
4205
+ React3.useEffect(() => {
4206
+ if (field.value && !date) {
4207
+ setDate(new Date(field.value));
4208
+ setIsValid(isValidField(input, form));
4209
+ }
4210
+ }, [field.value]);
4211
+ const handleSelect = (selectedDate) => {
4212
+ setDate(selectedDate);
4213
+ handleOnChage(selectedDate, input, field);
4214
+ };
4215
+ return /* @__PURE__ */ jsxs(FormItem, { children: [
4216
+ /* @__PURE__ */ jsx(FormLabel, { children: /* @__PURE__ */ jsx("b", { children: input.label }) }),
4217
+ /* @__PURE__ */ jsxs(Popover, { children: [
4218
+ /* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(InputGroup, { className: "flex flex-row gap-1", children: /* @__PURE__ */ jsxs(
4219
+ Button,
4220
+ {
4221
+ variant: "outline",
4222
+ className: cn(
4223
+ "w-full justify-start text-left py-0.5 ",
4224
+ !date && "text-muted-foreground"
4225
+ ),
4226
+ children: [
4227
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-1 items-center gap-1 justify-start text-left ", children: [
4199
4228
  /* @__PURE__ */ jsx(CalendarIcon, {}),
4200
4229
  date ? format(date, "PPP") : /* @__PURE__ */ jsx("span", { children: input.placeHolder ?? "Fecha" })
4201
- ]
4202
- }
4203
- ) }) }),
4204
- /* @__PURE__ */ jsx(PopoverContent, { className: "w-auto p-0", children: /* @__PURE__ */ jsx(
4205
- Calendar,
4206
- {
4207
- mode: "single",
4208
- selected: date,
4209
- onSelect: handleSelect,
4210
- initialFocus: true
4211
- }
4212
- ) })
4213
- ] }),
4214
- /* @__PURE__ */ jsx(FormDescription, { children: input.description }),
4215
- /* @__PURE__ */ jsx(FormMessage, {})
4216
- ] });
4217
- }
4218
- },
4219
- input.name
4220
- );
4221
- return /* @__PURE__ */ jsx(Fragment, { children: formField });
4222
- }
4230
+ ] }),
4231
+ (iconsRight.length > 0 || textRight || autoValidate) && /* @__PURE__ */ jsxs(Fragment, { children: [
4232
+ textRight && /* @__PURE__ */ jsx(InputGroupText, { children: textRight }),
4233
+ iconsRight.map((IconComponent, index) => /* @__PURE__ */ jsx(IconComponent, { size: 24, className: "w-6! h-6!" }, index)),
4234
+ autoValidate && /* @__PURE__ */ jsx("div", { children: isSubmitting ? iconLoadingState : isValid2 ? iconValidState : iconInvalidState })
4235
+ ] })
4236
+ ]
4237
+ }
4238
+ ) }) }) }),
4239
+ /* @__PURE__ */ jsx(PopoverContent, { className: "w-auto p-0", children: /* @__PURE__ */ jsx(
4240
+ Calendar,
4241
+ {
4242
+ mode: "single",
4243
+ selected: date,
4244
+ onSelect: handleSelect,
4245
+ initialFocus: true
4246
+ }
4247
+ ) })
4248
+ ] }),
4249
+ /* @__PURE__ */ jsx(FormDescription, { children: input.description }),
4250
+ /* @__PURE__ */ jsx(FormMessage, {})
4251
+ ] });
4252
+ }
4253
+ },
4254
+ input.name
4255
+ );
4256
+ return /* @__PURE__ */ jsx(Fragment, { children: formField });
4223
4257
  };
4224
4258
  var DateTimeInput = class extends BaseInput {
4225
4259
  render() {
@@ -4229,7 +4263,7 @@ var DateTimeInput = class extends BaseInput {
4229
4263
  };
4230
4264
  var FieldDateTimeInput = ({ form, input, isSubmitting }) => {
4231
4265
  const groupConfig = input.inputGroupConfig;
4232
- const autoValidate = groupConfig?.autoValidIcons;
4266
+ const autoValidate = groupConfig?.autoValidIcons ?? input.zodType ? true : false;
4233
4267
  const iconValidState = /* @__PURE__ */ jsx(CircleCheck, { style: { color: "#00bf3e" } });
4234
4268
  const iconInvalidState = /* @__PURE__ */ jsx(CircleX, { style: { color: "#ff8080" } });
4235
4269
  const iconLoadingState = /* @__PURE__ */ jsx(Loader2, { className: "animate-spin", style: { color: "#1e90ff" } });
@@ -4280,7 +4314,7 @@ var FieldDateTimeInput = ({ form, input, isSubmitting }) => {
4280
4314
  ),
4281
4315
  (iconsRight.length > 0 || textRight || autoValidate) && /* @__PURE__ */ jsxs(InputGroupAddon, { align: "inline-end", children: [
4282
4316
  textRight && /* @__PURE__ */ jsx(InputGroupText, { children: textRight }),
4283
- iconsRight.map((IconComponent, index) => /* @__PURE__ */ jsx(IconComponent, { size: 20 }, index)),
4317
+ iconsRight.map((IconComponent, index) => /* @__PURE__ */ jsx(IconComponent, { size: 24 }, index)),
4284
4318
  autoValidate && /* @__PURE__ */ jsx("div", { children: isSubmitting ? iconLoadingState : isValid2 ? iconValidState : iconInvalidState })
4285
4319
  ] })
4286
4320
  ] }) }),
@@ -4493,34 +4527,40 @@ var FieldKeyValueList = ({ form, input, isSubmitting }) => {
4493
4527
  return /* @__PURE__ */ jsxs(FormItem, { className: input.className, children: [
4494
4528
  /* @__PURE__ */ jsx(FormLabel, { children: /* @__PURE__ */ jsx("b", { children: input.label }) }),
4495
4529
  /* @__PURE__ */ jsx(FormMessage, {}),
4496
- /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3 rounded-xl p-3 ", children: [
4530
+ /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3 rounded-xl ", children: [
4497
4531
  pairs.length === 0 && /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "No pairs have been added yet." }),
4498
4532
  pairs.map((pair, index) => /* @__PURE__ */ jsxs(
4499
4533
  "div",
4500
4534
  {
4501
- className: "flex gap-2 items-center",
4535
+ className: "flex flex-row w-full gap-2 items-center py-0.5",
4502
4536
  children: [
4503
- /* @__PURE__ */ jsx(
4504
- Input,
4505
- {
4506
- placeholder: "Key",
4507
- value: pair.key,
4508
- disabled: isSubmitting,
4509
- onChange: (e) => handleChange(index, "key", e.target.value),
4510
- className: "w-1/2"
4511
- }
4512
- ),
4513
- /* @__PURE__ */ jsx(
4514
- Input,
4515
- {
4516
- placeholder: "Value",
4517
- value: pair.value,
4518
- disabled: isSubmitting,
4519
- onChange: (e) => handleChange(index, "value", e.target.value),
4520
- className: "w-1/2"
4521
- }
4522
- ),
4523
- /* @__PURE__ */ jsx(
4537
+ /* @__PURE__ */ jsxs(ButtonGroup, { className: "w-full", children: [
4538
+ /* @__PURE__ */ jsx(ButtonGroupText, { asChild: true, children: /* @__PURE__ */ jsx(Label$1, { htmlFor: "key", children: "Key" }) }),
4539
+ /* @__PURE__ */ jsx(InputGroup, { children: /* @__PURE__ */ jsx(
4540
+ InputGroupInput,
4541
+ {
4542
+ placeholder: "Key",
4543
+ value: pair.key,
4544
+ disabled: isSubmitting,
4545
+ onChange: (e) => handleChange(index, "key", e.target.value),
4546
+ className: "flex-1"
4547
+ }
4548
+ ) })
4549
+ ] }),
4550
+ /* @__PURE__ */ jsxs(ButtonGroup, { className: "w-full", children: [
4551
+ /* @__PURE__ */ jsx(ButtonGroupText, { asChild: true, children: /* @__PURE__ */ jsx(Label$1, { htmlFor: "value", children: "Value" }) }),
4552
+ /* @__PURE__ */ jsx(InputGroup, { children: /* @__PURE__ */ jsx(
4553
+ InputGroupInput,
4554
+ {
4555
+ placeholder: "Value",
4556
+ value: pair.value,
4557
+ disabled: isSubmitting,
4558
+ onChange: (e) => handleChange(index, "value", e.target.value),
4559
+ className: "flex-1"
4560
+ }
4561
+ ) })
4562
+ ] }),
4563
+ input.isRemovebleOption && /* @__PURE__ */ jsx(
4524
4564
  Button,
4525
4565
  {
4526
4566
  type: "button",
@@ -4658,7 +4698,7 @@ var TextInputGroup = class extends BaseInput {
4658
4698
  var FieldTextGroup = ({ form, input, isSubmitting }) => {
4659
4699
  const groupConfig = input.inputGroupConfig;
4660
4700
  const infoTooltip = input?.infoTooltip;
4661
- const autoValidate = groupConfig?.autoValidIcons;
4701
+ const autoValidate = groupConfig?.autoValidIcons ?? input.zodType ? true : false;
4662
4702
  const iconValidState = /* @__PURE__ */ jsx(CircleCheck, { style: { color: "#00bf3e" } });
4663
4703
  const iconInvalidState = /* @__PURE__ */ jsx(CircleX, { style: { color: "#ff8080" } });
4664
4704
  const iconLoadingState = /* @__PURE__ */ jsx(Loader2, { className: "animate-spin", style: { color: "#1e90ff" } });
@@ -4666,11 +4706,7 @@ var FieldTextGroup = ({ form, input, isSubmitting }) => {
4666
4706
  const iconsLeft = groupConfig?.iconsLeft ?? [];
4667
4707
  const textLeft = groupConfig?.textLeft;
4668
4708
  const textRight = groupConfig?.textRight;
4669
- const [isValid2, setIsValid] = useState(() => {
4670
- const value = form.getValues(input.name);
4671
- const fieldState = form.getFieldState(input.name);
4672
- return !fieldState.error && value !== void 0 && value !== "";
4673
- });
4709
+ const [isValid2, setIsValid] = useState(isValidField(input, form));
4674
4710
  const [showPassword, setShowPassword] = useState(false);
4675
4711
  const isPasswordField = input.keyboardType === "password" /* PASSWORD */;
4676
4712
  const isNumberField = input.keyboardType === "number" /* NUMBER */;
@@ -4680,9 +4716,8 @@ var FieldTextGroup = ({ form, input, isSubmitting }) => {
4680
4716
  {
4681
4717
  control: form.control,
4682
4718
  name: input.name,
4683
- render: ({ field, fieldState }) => {
4684
- const validNow = !fieldState.error && field.value !== void 0 && field.value !== "";
4685
- if (validNow !== isValid2) setIsValid(validNow);
4719
+ render: ({ field }) => {
4720
+ setIsValid(isValidField(input, form));
4686
4721
  return /* @__PURE__ */ jsxs(FormItem, { className: input.className, children: [
4687
4722
  /* @__PURE__ */ jsx(FormLabel, { children: /* @__PURE__ */ jsx("b", { children: input.label }) }),
4688
4723
  /* @__PURE__ */ jsx(FormControl, { className: "shadow-lg", children: /* @__PURE__ */ jsxs(InputGroup, { children: [
@@ -4707,6 +4742,7 @@ var FieldTextGroup = ({ form, input, isSubmitting }) => {
4707
4742
  }
4708
4743
  handleOnChage(value, input, field);
4709
4744
  field.onChange(value);
4745
+ isValidField(input, form);
4710
4746
  }
4711
4747
  }
4712
4748
  ),
@@ -4861,7 +4897,7 @@ var FieldRepeater = ({ form, input, isSubmitting }) => {
4861
4897
  fields.map((item, index) => /* @__PURE__ */ jsxs(
4862
4898
  "div",
4863
4899
  {
4864
- className: "border p-3 rounded-md flex flex-col gap-3",
4900
+ className: "border p-3 rounded-md flex flex-col gap-4 py-3",
4865
4901
  children: [
4866
4902
  input.repeaterFields?.map((fieldGroup, groupIndex) => {
4867
4903
  const group = Array.isArray(fieldGroup) ? fieldGroup : [fieldGroup];
@@ -5523,7 +5559,7 @@ var FieldStringValueList = ({ form, input, isSubmitting }) => {
5523
5559
  items.map((value, index) => /* @__PURE__ */ jsxs(
5524
5560
  "div",
5525
5561
  {
5526
- className: "flex gap-2 items-center",
5562
+ className: "flex items-center gap-4 py-2",
5527
5563
  children: [
5528
5564
  /* @__PURE__ */ jsx(
5529
5565
  Input,
@@ -5784,10 +5820,10 @@ var FieldText = ({ input, form, isSubmitting }) => {
5784
5820
  var TimeInput = class extends BaseInput {
5785
5821
  render() {
5786
5822
  const { input, form, isSubmitting } = this;
5787
- return /* @__PURE__ */ jsx(FieldTimeInput, { input, form, isSubmitting });
5823
+ return /* @__PURE__ */ jsx(FieldTimeInput2, { input, form, isSubmitting });
5788
5824
  }
5789
5825
  };
5790
- var FieldTimeInput = ({ form, input, isSubmitting }) => {
5826
+ var FieldTimeInput2 = ({ form, input, isSubmitting }) => {
5791
5827
  const groupConfig = input.inputGroupConfig;
5792
5828
  const autoValidate = groupConfig?.autoValidIcons;
5793
5829
  const iconValidState = /* @__PURE__ */ jsx(CircleCheck, { style: { color: "#00bf3e" } });
@@ -5895,6 +5931,7 @@ var inputMap = {
5895
5931
  };
5896
5932
  var InputFactory = class {
5897
5933
  static create(input, form, isSubmitting = false) {
5934
+ input.form = form;
5898
5935
  const inputType = input.inputType ?? "text" /* TEXT */;
5899
5936
  const InputClass = inputMap[inputType] ?? TextInput;
5900
5937
  const instance = new InputClass(input, form, isSubmitting);
@@ -6044,6 +6081,7 @@ var DynamicForm = ({
6044
6081
  fields,
6045
6082
  readOnly = false,
6046
6083
  record = {},
6084
+ onAnyFieldChange,
6047
6085
  onSubmit,
6048
6086
  onClick,
6049
6087
  extraValidations,
@@ -6064,7 +6102,7 @@ var DynamicForm = ({
6064
6102
  }) => {
6065
6103
  const [isPending, startTransition] = useTransition();
6066
6104
  const schema = useMemo(() => {
6067
- const allFields = flattenFields(fields);
6105
+ const allFields = flattenFields(fields, onAnyFieldChange);
6068
6106
  return getDynamicSchema(allFields, extraValidations);
6069
6107
  }, [fields, extraValidations]);
6070
6108
  const resolver = zodResolver(schema);
@@ -6075,7 +6113,7 @@ var DynamicForm = ({
6075
6113
  });
6076
6114
  useEffect(() => {
6077
6115
  form.reset(initialValues);
6078
- }, [initialValues, form]);
6116
+ }, []);
6079
6117
  const handleSubmit = (data) => {
6080
6118
  if (readOnly) return;
6081
6119
  startTransition(() => {
@@ -6472,6 +6510,6 @@ var GenericFilter = ({
6472
6510
  ) }) });
6473
6511
  };
6474
6512
 
6475
- export { Accordion, AccordionContent, AccordionGroupedSwitchInput, AccordionGroupedSwitches, AccordionItem, AccordionTrigger, Alert, AlertDescription, AlertTitle, Badge, BaseInput, Button, ButtonGroup, ButtonGroupInput, ButtonGroupSeparator, ButtonGroupText, Calendar, CalendarDayButton, Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, CheckListInput, Checkbox, CheckboxInput, ColorCnInput, ColorInput, ComboboxInput, Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, CurrencyInput, CustomAlert, DateInput, DateTimeInput, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DynamicForm, DynamicFormExample, Field, FieldButtonGroup, FieldContent, FieldCurrency, FieldDateTimeInput, FieldDescription, FieldError, FieldFileMultiUpload, FieldGroup, FieldKeyValueList, FieldLabel, FieldLegend, FieldRepeater, FieldSeparator, FieldSet, FieldSimpleCheckList, FieldSlider, FieldStringValueList, FieldTextGroup, FieldTimeInput, FieldTitle, FileInput, FileMultiUploadInput, Form, FormControl, FormDescription, FormErrorsAlert, FormField, FormFieldsGrid, FormItem, FormLabel, FormMessage, GenericFilter, GroupedSwitchInput, GroupedSwitches, Input, InputFactory, InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput, InputGroupText, InputGroupTextarea, InputList, InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot, InputTypes, KeyValueListInput, Label, MultiSelectInput, NumberInput, OTPInput2 as OTPInput, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, RadioGroup, RadioGroupInput, RadioGroupItem, RepeaterInput, RepeaterTabsInput, ResizableHandle, ResizablePanel, ResizablePanelGroup, ScrollArea, ScrollBar, Select, SelectContent, SelectGroup, SelectInput, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator, SimpleCheckListInput, Slider, SliderInput, SortableListInput, StringValueListInput, Switch, SwitchInput, Tabs, TabsContent, TabsList, TabsTrigger, TagInput, TextAreaInput, TextInput, TextInputGroup, TextInputType, Textarea, TimeInput, Toaster, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, badgeVariants, buttonGroupVariants, buttonVariants, cn, entitiesToGroupedOption, entitiesToInputOption, entityToGroupedOption, entityToInputOption, flattenFields, getDefaultValues, getDynamicSchema, getFieldLabel, handleOnChage, inputFieldComp, mockFields, useFormField, validationMessages };
6513
+ export { Accordion, AccordionContent, AccordionGroupedSwitchInput, AccordionGroupedSwitches, AccordionItem, AccordionTrigger, Alert, AlertDescription, AlertTitle, Badge, BaseInput, Button, ButtonGroup, ButtonGroupInput, ButtonGroupSeparator, ButtonGroupText, Calendar, CalendarDayButton, Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, CheckListInput, Checkbox, CheckboxInput, ColorCnInput, ColorInput, ComboboxInput, Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, CurrencyInput, CustomAlert, DateInput, DateTimeInput, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DynamicForm, DynamicFormExample, Field, FieldButtonGroup, FieldContent, FieldCurrency, FieldDateTimeInput, FieldDescription, FieldError, FieldFileMultiUpload, FieldGroup, FieldKeyValueList, FieldLabel, FieldLegend, FieldRepeater, FieldSeparator, FieldSet, FieldSimpleCheckList, FieldSlider, FieldStringValueList, FieldTextGroup, FieldTimeInput2 as FieldTimeInput, FieldTitle, FileInput, FileMultiUploadInput, Form, FormControl, FormDescription, FormErrorsAlert, FormField, FormFieldsGrid, FormItem, FormLabel, FormMessage, GenericFilter, GroupedSwitchInput, GroupedSwitches, Input, InputFactory, InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput, InputGroupText, InputGroupTextarea, InputList, InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot, InputTypes, KeyValueListInput, Label, MultiSelectInput, NumberInput, OTPInput2 as OTPInput, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, RadioGroup, RadioGroupInput, RadioGroupItem, RepeaterInput, RepeaterTabsInput, ResizableHandle, ResizablePanel, ResizablePanelGroup, ScrollArea, ScrollBar, Select, SelectContent, SelectGroup, SelectInput, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator, SimpleCheckListInput, Slider, SliderInput, SortableListInput, StringValueListInput, Switch, SwitchInput, Tabs, TabsContent, TabsList, TabsTrigger, TagInput, TextAreaInput, TextInput, TextInputGroup, TextInputType, Textarea, TimeInput, Toaster, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, badgeVariants, buttonGroupVariants, buttonVariants, cn, entitiesToGroupedOption, entitiesToInputOption, entityToGroupedOption, entityToInputOption, flattenFields, getDefaultValues, getDynamicSchema, getFieldLabel, handleOnChage, inputFieldComp, isValidField, mockFields, useFormField, validationMessages };
6476
6514
  //# sourceMappingURL=index.mjs.map
6477
6515
  //# sourceMappingURL=index.mjs.map