ping-identity
    Preparing search index...

    Function useDaVinciForm

    Headless collector form helper hook for DaVinci nodes.

    • Headless collector form helper for DaVinci nodes.

      Parameters

      Returns DaVinciFormResult

      Normalized fields, managed values, and submit planning helpers.

      Manages collector form state and submit planning for the active DaVinci node. Pair with useDaVinci (or DaVinciProvider) for flow navigation.

      Whenever node changes identity (e.g. after next() resolves to a new ContinueNode), the form automatically resets its value map and reseeds collector defaults for the new node's fields — you do not need to call reset() manually on navigation.

      Tapping a FlowCollector (ACTION, FLOW_BUTTON, FLOW_LINK) via setValue/setValueByType immediately calls next() with only that key, bypassing all other field values — no manual next() call required. submitFlow is the explicit equivalent for flow keys not wired to a setValue call directly.

      Basic usage with an explicit client:

      const { node, next } = useDaVinci(client);
      const form = useDaVinciForm(node);

      form.setValueByType('TEXT', 'alice');
      if (form.canSubmit) {
      await next(form.input);
      }

      Inside a <DaVinciProvider>, next is resolved from context, so tapping a FlowCollector via setValue auto-submits without any extra wiring:

      const { node } = useDaVinci();
      const form = useDaVinciForm(node);

      // "forgotPassword" is a FLOW_BUTTON collector key — setValue advances the
      // flow immediately, bypassing form.values entirely.
      await form.setValue('forgotPassword', 'forgotPassword');

      Rendering fields by kind, independent of the exact collector type:

      const form = useDaVinciForm(node);

      form.fields.map((field) => {
      switch (field.kind) {
      case 'text':
      return (
      <TextInput
      key={field.key}
      value={(form.values[field.key] as string) ?? ''}
      onChangeText={(text) => form.setValue(field.key, text)}
      />
      );
      case 'password':
      return (
      <TextInput
      key={field.key}
      secureTextEntry
      value={(form.values[field.key] as string) ?? ''}
      onChangeText={(text) => form.setValue(field.key, text)}
      />
      );
      default:
      return null;
      }
      });

      Passing next explicitly when used outside a <DaVinciProvider> — required for submitFlow to work in that setup:

      const { node, next } = useDaVinci(client);
      const form = useDaVinciForm(node, { next });
      await form.submitFlow('forgotPassword');