constitutional-coralC
Refine12mo ago
4 replies
constitutional-coral

Edit Form

Data provider resources and routes are correctly implemented.

Here is my edit component :

import { Nullable, Product, IProductFormData } from "@/interfaces";
import { ProductCreateForm } from "../../components";
import { useForm } from "@refinedev/react-hook-form";
import { FormProvider } from "react-hook-form";
import { HttpError, useOne } from "@refinedev/core";
import { zodResolver } from "@hookform/resolvers/zod";
import { productFormSchema } from "@/utils/zod/productFormValidation";
import { DevTool } from "@hookform/devtools";

export const ProductEdit = () => {
  const methods = useForm<Product, HttpError, Nullable<IProductFormData>>({
    // defaultValues: data?.data?.data[0] as Nullable<IProductFormData>,
    refineCoreProps: {
      redirect: false,
    },
    defaultValues: async () => {
      //@ts-ignore
      const response = await data_provider_typed.getOne({
        resource: "products",
        id: 146,
      });
      return response.data;
    },
  
    resolver: zodResolver(productFormSchema)
  });

  return (
    <FormProvider {...methods}>
      <DevTool control={methods.control} />
      <Edit isLoading={isLoading} saveButtonProps={saveButtonProps}>
<TextFieldElement
            name="name"
            label={t("products.fields.name")}
            fullWidth
            autoFocus
          />  
          <TextFieldElement
            name="description"
            label={t("products.fields.description")}
            multiline
            rows={4}
            fullWidth
          />

</Edit>
    </FormProvider>
  );
};


Form elements are not getting the default values in here
Was this page helpful?