Antd React Form使用Radio嵌套多个Select和Input的处理

使用Antd React Form使用Radio会遇到嵌套多个Select和Input的处理,需要多层嵌套和处理默认事件和冒泡,具体实现过程直接上代码。

实现效果布局如下图

代码

javascript 复制代码
<Form
    name="basic"
    form={form}
    labelWrap
    {...formItemLayoutSpan(5, 19)}
    onFinish={onFinish}
    autoComplete="off"
    >
    <Row gutter={gutterValue}>
        <Col span={24}>
             <Form.Item name="isConfirm" noStyle>
                <Radio.Group>
                  <Space direction="vertical">
                    <Radio value={1}>
                      <Space wrap>
                        已定级备案,第
                        <span onClick={eventPrevent}>
                          <Form.Item
                            noStyle
                            shouldUpdate={(prevValues, currentValues) =>
                              (prevValues as any)?.isConfirm !==
                              (currentValues as any)?.isConfirm
                            }
                          >
                            {({ getFieldValue }) => (
                              <FormItemSelect
                                className="level-select"
                                noStyle={true}
                                options={
                                  confidentialLevelNumberDict as optionsDict[]
                                }
                                disabled={getFieldValue("isConfirm") === 2}
                                name={"1111"}
                              />
                            )}
                          </Form.Item>
                        </span>
                        级(一至四),S
                        <span onClick={eventPrevent}>
                          <Form.Item
                            noStyle
                            shouldUpdate={(prevValues, currentValues) =>
                              (prevValues as any)?.isKey !==
                              (currentValues as any)?.isKey
                            }
                          >
                            {({ getFieldValue }) => (
                              <FormItemSelect
                                className="level-select"
                                noStyle={true}
                                options={
                                  confidentialLevelNumberDict as optionsDict[]
                                }
                                disabled={getFieldValue("isConfirm") === 2}
                                name={"112222"}
                              />
                            )}
                          </Form.Item>
                        </span>
                        A
                        <span onClick={eventPrevent}>
                          <Form.Item
                            noStyle
                            shouldUpdate={(prevValues, currentValues) =>
                              (prevValues as any)?.isKey !==
                              (currentValues as any)?.isKey
                            }
                          >
                            {({ getFieldValue }) => (
                              <FormItemSelect
                                className="level-select"
                                noStyle={true}
                                options={
                                  confidentialLevelNumberDict as optionsDict[]
                                }
                                disabled={getFieldValue("isConfirm") === 2}
                                name={"11223333"}
                              />
                            )}
                          </Form.Item>
                        </span>
                        G
                        <span onClick={eventPrevent}>
                          <Form.Item
                            noStyle
                            shouldUpdate={(prevValues, currentValues) =>
                              (prevValues as any)?.isKey !==
                              (currentValues as any)?.isKey
                            }
                          >
                            {({ getFieldValue }) => (
                              <FormItemSelect
                                className="level-select"
                                noStyle={true}
                                options={
                                  confidentialLevelNumberDict as optionsDict[]
                                }
                                disabled={getFieldValue("isConfirm") === 2}
                                name={"11255555"}
                              />
                            )}
                          </Form.Item>
                        </span>
                      </Space>
                      <div className="mt-4">
                        <span onClick={eventPrevent}>
                          <Space>
                            备案证明编号:
                            <Form.Item
                              noStyle
                              shouldUpdate={(prevValues, currentValues) =>
                                (prevValues as any)?.isConfirm !==
                                (currentValues as any)?.isConfirm
                              }
                            >
                              {({ getFieldValue }) => (
                                <FormItemInput
                                  noStyle={true}
                                  disabled={getFieldValue("isConfirm") === 1}
                                  name={"33666"}
                                />
                              )}
                            </Form.Item>
                          </Space>
                        </span>
                      </div>
                    </Radio>
                    <Radio value={2}>
                      <Space wrap>
                        未定级,本次密评依据GB/T 39786---2021《信息安全技术
                        信息系统密码应用基本要求》第
                        <span
                          onClick={(e) => {
                            e.stopPropagation();
                            e.preventDefault();
                          }}
                        >
                          <Form.Item
                            noStyle
                            shouldUpdate={(prevValues, currentValues) =>
                              (prevValues as any)?.isConfirm !==
                              (currentValues as any)?.isConfirm
                            }
                          >
                            {({ getFieldValue }) => (
                              <FormItemSelect
                                noStyle={true}
                                className="level-select"
                                options={
                                  confidentialLevelNumberDict as optionsDict[]
                                }
                                disabled={getFieldValue("isConfirm") === 1}
                                name={"77777"}
                              />
                            )}
                          </Form.Item>
                        </span>
                        级(一至四)信息系统要求
                      </Space>
                    </Radio>
                  </Space>
                </Radio.Group>
              </Form.Item>
         </Col>
      </Row>
</Form>
javascript 复制代码
const eventPrevent = (event: any) => {
  event.preventDefault();
  event.stopPropagation();
};

export { eventPrevent };


.level-select {
   width: 84px !important;
}
相关推荐
lilu88888881 小时前
AI代码生成器赋能房地产:ScriptEcho如何革新VR/AR房产浏览体验
前端·人工智能·ar·vr
LCG元1 小时前
Vue.js组件开发-实现对视频预览
前端·vue.js·音视频
傻小胖1 小时前
shallowRef和shallowReactive的用法以及使用场景和ref和reactive的区别
javascript·vue.js·ecmascript
阿芯爱编程1 小时前
vue3 react区别
前端·react.js·前端框架
烛.照1031 小时前
Nginx部署的前端项目刷新404问题
运维·前端·nginx
YoloMari2 小时前
组件中的emit
前端·javascript·vue.js·微信小程序·uni-app
CaptainDrake2 小时前
力扣 Hot 100 题解 (js版)更新ing
javascript·算法·leetcode
浪浪山小白兔2 小时前
HTML5 Web Worker 的使用与实践
前端·html·html5
疯狂小料3 小时前
React 路由导航与传参详解
前端·react.js·前端框架
追光少年33223 小时前
Learning Vue 读书笔记 Chapter 2
前端·javascript·vue.js·vue3