@formality-ui/react 0.2.4 → 0.2.5

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.cts CHANGED
@@ -593,6 +593,14 @@ interface FormProps<TFieldValues extends FieldValues = FieldValues> {
593
593
  * (`false` for immediate, or a number for a per-field delay).
594
594
  */
595
595
  debounce?: number | false;
596
+ /**
597
+ * React Hook Form validation trigger `mode`, forwarded to `useForm({ mode })`.
598
+ * One of `'onChange'` (default) | `'onBlur'` | `'onSubmit'` | `'onTouched'` |
599
+ * `'all'`. Honored as-is — auto-save is mode-agnostic: its validity gates
600
+ * trigger validation of the touched fields themselves via `methods.trigger`
601
+ * (which ignores `mode`), so it works under any mode. See PRD §12.
602
+ */
603
+ mode?: "onChange" | "onBlur" | "onSubmit" | "onTouched" | "all";
596
604
  /** Form-level validation */
597
605
  validate?: (values: Partial<TFieldValues>) => Record<string, string> | Promise<Record<string, string>>;
598
606
  }
@@ -644,7 +652,7 @@ interface FormRenderAPI<TFieldValues extends FieldValues = FieldValues> {
644
652
  * </Form>
645
653
  * ```
646
654
  */
647
- declare function Form<TFieldValues extends FieldValues = FieldValues>({ children, config, formConfig, onSubmit, record, autoSave, debounce: debounceMs, validate, }: FormProps<TFieldValues>): JSX.Element;
655
+ declare function Form<TFieldValues extends FieldValues = FieldValues>({ children, config, formConfig, onSubmit, record, autoSave, debounce: debounceMs, mode, validate, }: FormProps<TFieldValues>): JSX.Element;
648
656
 
649
657
  /**
650
658
  * Field component props.
package/dist/index.d.ts CHANGED
@@ -593,6 +593,14 @@ interface FormProps<TFieldValues extends FieldValues = FieldValues> {
593
593
  * (`false` for immediate, or a number for a per-field delay).
594
594
  */
595
595
  debounce?: number | false;
596
+ /**
597
+ * React Hook Form validation trigger `mode`, forwarded to `useForm({ mode })`.
598
+ * One of `'onChange'` (default) | `'onBlur'` | `'onSubmit'` | `'onTouched'` |
599
+ * `'all'`. Honored as-is — auto-save is mode-agnostic: its validity gates
600
+ * trigger validation of the touched fields themselves via `methods.trigger`
601
+ * (which ignores `mode`), so it works under any mode. See PRD §12.
602
+ */
603
+ mode?: "onChange" | "onBlur" | "onSubmit" | "onTouched" | "all";
596
604
  /** Form-level validation */
597
605
  validate?: (values: Partial<TFieldValues>) => Record<string, string> | Promise<Record<string, string>>;
598
606
  }
@@ -644,7 +652,7 @@ interface FormRenderAPI<TFieldValues extends FieldValues = FieldValues> {
644
652
  * </Form>
645
653
  * ```
646
654
  */
647
- declare function Form<TFieldValues extends FieldValues = FieldValues>({ children, config, formConfig, onSubmit, record, autoSave, debounce: debounceMs, validate, }: FormProps<TFieldValues>): JSX.Element;
655
+ declare function Form<TFieldValues extends FieldValues = FieldValues>({ children, config, formConfig, onSubmit, record, autoSave, debounce: debounceMs, mode, validate, }: FormProps<TFieldValues>): JSX.Element;
648
656
 
649
657
  /**
650
658
  * Field component props.
package/dist/index.js CHANGED
@@ -147,6 +147,7 @@ function Form({
147
147
  record,
148
148
  autoSave = false,
149
149
  debounce: debounceMs = 1e3,
150
+ mode,
150
151
  validate
151
152
  }) {
152
153
  const providerConfig = useConfigContext();
@@ -164,7 +165,7 @@ function Form({
164
165
  return resolveAllInitialValues(config, mergedInputs, record ?? {});
165
166
  }, [config, mergedInputs, record]);
166
167
  const methods = useForm({
167
- mode: "onChange",
168
+ mode: mode ?? "onChange",
168
169
  defaultValues,
169
170
  values: record
170
171
  });
@@ -404,9 +405,20 @@ function Form({
404
405
  if (!validationsComplete || executionVersionRef.current !== executionVersion) {
405
406
  return;
406
407
  }
407
- for (const fieldName of changedFields) {
408
- const fieldState = methods.getFieldState(fieldName);
409
- if (fieldState.error) {
408
+ const changedArray = [...changedFields];
409
+ if (changedArray.length > 0) {
410
+ const changedValid = await methods.trigger(changedArray);
411
+ if (executionVersionRef.current !== executionVersion) {
412
+ return;
413
+ }
414
+ if (!changedValid) {
415
+ return;
416
+ }
417
+ const changedValidationsComplete = await waitForFieldValidation(
418
+ changedArray,
419
+ executionVersion
420
+ );
421
+ if (!changedValidationsComplete || executionVersionRef.current !== executionVersion) {
410
422
  return;
411
423
  }
412
424
  }