genetic-orange
genetic-orange7mo ago

how to set current value to radio button

how to add current value to AntDesign Edit Component import React from "react"; import { IResourceComponentsProps } from "@refinedev/core"; import { Edit, useForm } from "@refinedev/antd"; import { Form, Input, Radio } from "antd"; export const AccountEdit: React.FC<IResourceComponentsProps> = () => { const { formProps, saveButtonProps, queryResult } = useForm(); const accountsData = queryResult?.data?.data; return ( <Edit saveButtonProps={saveButtonProps}> <Form {...formProps} layout="vertical"> <Form.Item label="Id" name={["id"]} rules={[ { required: true, }, ]} > <Input readOnly disabled /> </Form.Item> <Form.Item label="Username" name={["username"]} rules={[ { required: true, }, ]} > <Input /> </Form.Item> <Form.Item label="Email" name={["email"]} rules={[ { required: true, }, ]} > <Input /> </Form.Item> <Form.Item label="Role" name={["role"]} rules={[ { required: true, }, ]} > <Input /> </Form.Item> </Form> </Edit> ); };
2 Replies
kapa.ai
kapa.ai7mo ago
Hi @M Farhan Zachary. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To set the current value for a Radio button in Ant Design within the Refine Edit component, you can use the Radio.Group and Radio components from Ant Design. The name prop in Form.Item should match the field name in your data, and the value prop in each Radio should match the possible values for that field. Here's how you can modify your Role field to use a Radio button:
<Form.Item
label="Role"
name="role"
rules={[
{
required: true,
},
]}
>
<Radio.Group>
<Radio value="role1">Role 1</Radio>
<Radio value="role2">Role 2</Radio>
{/* Add more Radio components as needed */}
</Radio.Group>
</Form.Item>
<Form.Item
label="Role"
name="role"
rules={[
{
required: true,
},
]}
>
<Radio.Group>
<Radio value="role1">Role 1</Radio>
<Radio value="role2">Role 2</Radio>
{/* Add more Radio components as needed */}
</Radio.Group>
</Form.Item>
In this example, "role1" and "role2" should be replaced with the actual role values you have. When the form is loaded, the Radio button matching the current role value will be selected. Please note that the information provided is based on the general usage of Ant Design and Refine, and not directly extracted from the provided sources. For more specific information, you may want to refer to the Refine Documentation (https://refine.dev/docs) and Ant Design Documentation (https://ant.design/components/radio/). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai7mo ago
<@757407865391808603> kapa.ai is still learning and improving, please let us know how it did by reacting below