useForm function

ZardFormController useForm({
  1. required ZMap schema,
  2. Map<String, dynamic> defaultValues = const {},
  3. ValidationMode mode = ValidationMode.onSubmit,
  4. RevalidateMode revalidateMode = RevalidateMode.onChange,
  5. Duration debounce = Duration.zero,
  6. bool disabled = false,
  7. bool asyncValidation = false,
  8. bool excludeDisabledFromValues = false,
})

React-Hook-Form-style useForm hook. Creates a ZardFormController tied to the calling widget's lifecycle (disposed on unmount). Subscribes to the controller so form-level state flips (isSubmitting, isValid, etc.) cause a rebuild.

Pair with a ZardForm(form: form, ...) so descendant widgets/hooks can resolve the form via context. If your tree doesn't need that scoping, you can use the returned controller directly.

Implementation

ZardFormController useForm({
  required ZMap schema,
  Map<String, dynamic> defaultValues = const {},
  ValidationMode mode = ValidationMode.onSubmit,
  RevalidateMode revalidateMode = RevalidateMode.onChange,
  Duration debounce = Duration.zero,
  bool disabled = false,
  bool asyncValidation = false,
  bool excludeDisabledFromValues = false,
}) {
  final form = useMemoized(
    () => ZardFormController(
      schema: schema,
      defaultValues: defaultValues,
      mode: mode,
      revalidateMode: revalidateMode,
      debounce: debounce,
      disabled: disabled,
      asyncValidation: asyncValidation,
      excludeDisabledFromValues: excludeDisabledFromValues,
    ),
    const [],
  );
  useEffect(() => form.dispose, [form]);
  useListenable(form);
  return form;
}