Skip to main content
Version: 2.xx.xx

Custom Inputs

refine uses Ant Design's <Form> components to control and work with form data. Ant Design supports custom form items inside the <Form.Item> components. These items should be controllable via their value property and should implement onChange (or a custom callback name specified by <Form.Item>s [trigger] prop (https://ant.design/components/form/#Form.Item)).

For some data types, displaying and editing as plain text may cause user experience problems.

Custom components may be useful when working with markdown (with markdown editor), JSON based rich text (draft, quill like editors), and HTML (a HTML editor). It can be used in table columns and form fields

Refer to the Ant Design docs for more detailed information about <Form>. β†’

Example​

We will demonstrate how to use custom input fields for markdown data by adding a markdown editor to edit and create forms.

/src/pages/posts/edit.tsx
import React, { useState } from "react";
import {
Edit,
Form,
Input,
IResourceComponentsProps,
useForm,
} from "@pankod/refine";

import ReactMarkdown from "react-markdown";
import ReactMde from "react-mde";

import "react-mde/lib/styles/css/react-mde-all.css";

import { IPost } from "interfaces";

export const PostEdit: React.FC = (props) => {
const { formProps, saveButtonProps } = useForm<IPost>();

const [selectedTab, setSelectedTab] = useState<"write" | "preview">(
"write",
);

return (
<Edit {...props} saveButtonProps={saveButtonProps}>
<Form {...formProps} layout="vertical">
<Form.Item
label="Title"
name="title"
rules={[
{
required: true,
},
]}
>
<Input />
</Form.Item>
<Form.Item
label="Content"
name="content"
rules={[
{
required: true,
},
]}
>
<ReactMde
selectedTab={selectedTab}
onTabChange={setSelectedTab}
generateMarkdownPreview={(markdown) =>
Promise.resolve(
<ReactMarkdown>{markdown}</ReactMarkdown>,
)
}
/>
</Form.Item>
</Form>
</Edit>
);
};
Markdown input

Live Codesandbox Example​