@character-foundry/character-foundry 0.4.3-dev.1766103111 → 0.4.3-dev.1767230557

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.
@@ -518,6 +518,14 @@ export interface AutoFormProps<T extends z.ZodObject<z.ZodRawShape>> {
518
518
  onChange?: (values: z.infer<T>) => void;
519
519
  /** Called on form submit with validated data */
520
520
  onSubmit?: (values: z.infer<T>) => void | Promise<void>;
521
+ /** Called when validation fails during onChange */
522
+ onValidationError?: (error: z.ZodError) => void;
523
+ /**
524
+ * Called on every value change, regardless of validation status.
525
+ * Useful when you need to track raw user input before validation.
526
+ * The values may not conform to the schema type.
527
+ */
528
+ onRawChange?: (values: unknown) => void;
521
529
  /** UI hints for customizing field rendering */
522
530
  uiHints?: UIHints<z.infer<T>>;
523
531
  /** Custom field order (array of field names) */
@@ -592,7 +600,7 @@ export interface AutoFormProps<T extends z.ZodObject<z.ZodRawShape>> {
592
600
  * />
593
601
  * ```
594
602
  */
595
- export declare function AutoForm<T extends z.ZodObject<z.ZodRawShape>>({ schema, values, defaultValues, onChange, onSubmit, uiHints, fieldOrder, disabled, withSubmit, submitText, className, widgetRegistry, children, }: AutoFormProps<T>): react_jsx_runtime.JSX.Element;
603
+ export declare function AutoForm<T extends z.ZodObject<z.ZodRawShape>>({ schema, values, defaultValues, onChange, onSubmit, onValidationError, onRawChange, uiHints, fieldOrder, disabled, withSubmit, submitText, className, widgetRegistry, children, }: AutoFormProps<T>): react_jsx_runtime.JSX.Element;
596
604
  /**
597
605
  * Analyzed field information extracted from a Zod schema.
598
606
  */
@@ -518,6 +518,14 @@ export interface AutoFormProps<T extends z.ZodObject<z.ZodRawShape>> {
518
518
  onChange?: (values: z.infer<T>) => void;
519
519
  /** Called on form submit with validated data */
520
520
  onSubmit?: (values: z.infer<T>) => void | Promise<void>;
521
+ /** Called when validation fails during onChange */
522
+ onValidationError?: (error: z.ZodError) => void;
523
+ /**
524
+ * Called on every value change, regardless of validation status.
525
+ * Useful when you need to track raw user input before validation.
526
+ * The values may not conform to the schema type.
527
+ */
528
+ onRawChange?: (values: unknown) => void;
521
529
  /** UI hints for customizing field rendering */
522
530
  uiHints?: UIHints<z.infer<T>>;
523
531
  /** Custom field order (array of field names) */
@@ -592,7 +600,7 @@ export interface AutoFormProps<T extends z.ZodObject<z.ZodRawShape>> {
592
600
  * />
593
601
  * ```
594
602
  */
595
- export declare function AutoForm<T extends z.ZodObject<z.ZodRawShape>>({ schema, values, defaultValues, onChange, onSubmit, uiHints, fieldOrder, disabled, withSubmit, submitText, className, widgetRegistry, children, }: AutoFormProps<T>): react_jsx_runtime.JSX.Element;
603
+ export declare function AutoForm<T extends z.ZodObject<z.ZodRawShape>>({ schema, values, defaultValues, onChange, onSubmit, onValidationError, onRawChange, uiHints, fieldOrder, disabled, withSubmit, submitText, className, widgetRegistry, children, }: AutoFormProps<T>): react_jsx_runtime.JSX.Element;
596
604
  /**
597
605
  * Analyzed field information extracted from a Zod schema.
598
606
  */
@@ -1629,6 +1629,8 @@ function AutoForm({
1629
1629
  defaultValues,
1630
1630
  onChange,
1631
1631
  onSubmit,
1632
+ onValidationError,
1633
+ onRawChange,
1632
1634
  uiHints = {},
1633
1635
  fieldOrder,
1634
1636
  disabled = false,
@@ -1723,15 +1725,22 @@ function AutoForm({
1723
1725
  }, [values, reset, schemaDefaults, defaultValues]);
1724
1726
  const onChangeRef = useRef3(onChange);
1725
1727
  onChangeRef.current = onChange;
1728
+ const onValidationErrorRef = useRef3(onValidationError);
1729
+ onValidationErrorRef.current = onValidationError;
1730
+ const onRawChangeRef = useRef3(onRawChange);
1731
+ onRawChangeRef.current = onRawChange;
1726
1732
  const schemaRef = useRef3(schema);
1727
1733
  schemaRef.current = schema;
1728
1734
  useEffect2(() => {
1729
- if (!onChangeRef.current) return;
1735
+ if (!onChangeRef.current && !onValidationErrorRef.current && !onRawChangeRef.current) return;
1730
1736
  const subscription = watch((formValues, { type }) => {
1731
1737
  if (type !== "change") return;
1738
+ onRawChangeRef.current?.(formValues);
1732
1739
  const result = schemaRef.current.safeParse(formValues);
1733
- if (result.success && onChangeRef.current) {
1734
- onChangeRef.current(result.data);
1740
+ if (result.success) {
1741
+ onChangeRef.current?.(result.data);
1742
+ } else {
1743
+ onValidationErrorRef.current?.(result.error);
1735
1744
  }
1736
1745
  });
1737
1746
  return () => subscription.unsubscribe();