Apply form to multiple parent ids

I have an api where I have a list of some items, and each item has other sublists, in this case some controls. I need to create a form that shows the controls data for a selected item, and when the user clicks apply it opens a dialog that shows the changes, and most importantly it should have the option to select which items to apply the changes to (current item will be selected by default). How can I achieve that? I'm using Ant Design for ui.
2 Replies
kapa.ai
kapa.ai2w ago
Hi @Stormlight. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To achieve what you're describing with refine and Ant Design, you can use a combination of useForm and useModalForm hooks along with Ant Design components. Here's a high-level approach to implement this functionality: 1. Use useForm to create the main form for editing controls of a selected item. 2. Use useModalForm to create a modal dialog for applying changes to multiple items. 3. Implement a custom "Apply" button that opens the modal with the changes and item selection. Here's a basic example of how you might structure this:
import { useForm, useModalForm, Form, Modal, Button, Select } from "@refinedev/antd";
import { Table, Input } from "antd";

const EditControls = () => {
const { formProps, saveButtonProps, queryResult } = useForm({
// Configure this based on your API and resource
});

const {
modalProps,
formProps: applyFormProps,
show: showApplyModal
} = useModalForm({
// Configure this for applying changes
});

const handleApply = () => {
// Get the current form values
const values = formProps.form?.getFieldsValue();
// Show the apply modal
showApplyModal();
};

return (
<>
<Form {...formProps}>
{/* Your form fields for controls */}
<Form.Item name="controlName" label="Control Name">
<Input />
</Form.Item>
{/* More form items... */}

<Button onClick={handleApply}>Apply Changes</Button>
</Form>

<Modal {...modalProps} title="Apply Changes">
<Form {...applyFormProps}>
<Form.Item name="itemsToApply" label="Apply to Items">
<Select mode="multiple">
{/* Options for selecting items */}
</Select>
</Form.Item>
</Form>
</Modal>
</>
);
};
import { useForm, useModalForm, Form, Modal, Button, Select } from "@refinedev/antd";
import { Table, Input } from "antd";

const EditControls = () => {
const { formProps, saveButtonProps, queryResult } = useForm({
// Configure this based on your API and resource
});

const {
modalProps,
formProps: applyFormProps,
show: showApplyModal
} = useModalForm({
// Configure this for applying changes
});

const handleApply = () => {
// Get the current form values
const values = formProps.form?.getFieldsValue();
// Show the apply modal
showApplyModal();
};

return (
<>
<Form {...formProps}>
{/* Your form fields for controls */}
<Form.Item name="controlName" label="Control Name">
<Input />
</Form.Item>
{/* More form items... */}

<Button onClick={handleApply}>Apply Changes</Button>
</Form>

<Modal {...modalProps} title="Apply Changes">
<Form {...applyFormProps}>
<Form.Item name="itemsToApply" label="Apply to Items">
<Select mode="multiple">
{/* Options for selecting items */}
</Select>
</Form.Item>
</Form>
</Modal>
</>
);
};
This example provides a basic structure for what you're trying to achieve. You'll need to adapt it to your specific API and data structure. The useForm hook manages the main form for editing controls, while useModalForm handles the modal for applying changes to multiple items. For more detailed information on using these hooks, you can refer to the following refine documentation: - useForm Hook Documentation - useModalForm Hook Documentation These resources will provide you with more specific examples and options for customizing the behavior to fit your exact requirements. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2w ago
<@453354981907759115> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?