TanStackT
TanStack3mo ago
13 replies
popular-magenta

Exclude field from onSubmit and validators

Can I have a form field defined in defaultValues and use it in my code, but exclude it from the form onSubmit callback and exclude it from the validators? e.g:
ts 
  const form = useAppForm({
    defaultValues: {
      quantity: defaultDeliveryNoteLineFormData.quantity as number | null,
      deliveryNoteId: deliveryNoteId,
      partId: defaultDeliveryNoteLineFormData.partId as number | null,
      partReferenceId: defaultDeliveryNoteLineFormData.partReferenceId as number | null,
      sellOrderLineId: defaultDeliveryNoteLineFormData.sellOrderLineId as number | null,
    },
    validators: {
      onSubmit: createDeliveryNoteLineSchema,
    },
    onSubmit: async ({ value: deliveryNoteFormData }) => {
      const mutationResult = await createDeliveryNoteLineMutation({
        variables: { deliveryNoteLine: deliveryNoteFormData as CreateDeliveryNoteLine },
      });
      onSubmit?.(mutationResult);
    },
  });

I don't want partId to be part of value: deliveryNoteFormData variable and exclude it in the validators property too
Was this page helpful?