|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+import React, { useState } from 'react';
|
|
|
2
|
+import { Button, Form, Input, Radio } from 'antd';
|
|
|
3
|
+
|
|
|
4
|
+const FormComponent = () => {
|
|
|
5
|
+ const [form] = Form.useForm();
|
|
|
6
|
+ const [formLayout, setFormLayout] = useState('horizontal');
|
|
|
7
|
+
|
|
|
8
|
+ const onFormLayoutChange = ({ layout }) => {
|
|
|
9
|
+ setFormLayout(layout);
|
|
|
10
|
+ };
|
|
|
11
|
+
|
|
|
12
|
+ const onFinish = (values) => {
|
|
|
13
|
+ console.log('Form Submitted:', values); // ✅ Console
|
|
|
14
|
+ alert(`Form Submitted!\nField A: ${values.fieldA}\nField B: ${values.fieldB}`); // ✅ Alert
|
|
|
15
|
+ };
|
|
|
16
|
+
|
|
|
17
|
+ return (
|
|
|
18
|
+ <Form
|
|
|
19
|
+ layout={formLayout}
|
|
|
20
|
+ form={form}
|
|
|
21
|
+ initialValues={{ layout: formLayout }}
|
|
|
22
|
+ onValuesChange={onFormLayoutChange}
|
|
|
23
|
+ onFinish={onFinish}
|
|
|
24
|
+ style={{ maxWidth: formLayout === 'inline' ? 'none' : 600 }}
|
|
|
25
|
+ >
|
|
|
26
|
+ <Form.Item label="Form Layout" name="layout">
|
|
|
27
|
+ <Radio.Group value={formLayout}>
|
|
|
28
|
+ <Radio.Button value="horizontal">Horizontal</Radio.Button>
|
|
|
29
|
+ <Radio.Button value="vertical">Vertical</Radio.Button>
|
|
|
30
|
+ <Radio.Button value="inline">Inline</Radio.Button>
|
|
|
31
|
+ </Radio.Group>
|
|
|
32
|
+ </Form.Item>
|
|
|
33
|
+
|
|
|
34
|
+ <Form.Item label="Field A" name="fieldA">
|
|
|
35
|
+ <Input placeholder="Enter something" />
|
|
|
36
|
+ </Form.Item>
|
|
|
37
|
+
|
|
|
38
|
+ <Form.Item label="Field B" name="fieldB">
|
|
|
39
|
+ <Input placeholder="Enter something else" />
|
|
|
40
|
+ </Form.Item>
|
|
|
41
|
+
|
|
|
42
|
+ <Form.Item>
|
|
|
43
|
+ <Button type="primary" htmlType="submit">
|
|
|
44
|
+ Submit
|
|
|
45
|
+ </Button>
|
|
|
46
|
+ </Form.Item>
|
|
|
47
|
+ </Form>
|
|
|
48
|
+ );
|
|
|
49
|
+};
|
|
|
50
|
+
|
|
|
51
|
+export default FormComponent;
|