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;
}
相关推荐
野生的程序媛10 分钟前
重生之我在学Vue--第8天 Vue 3 UI 框架(Element Plus)
前端·vue.js·ui
前端付杰38 分钟前
从Vue源码解锁位运算符:提升代码效率的秘诀
前端·javascript·vue.js
然后就去远行吧39 分钟前
小程序 wxml 语法 —— 37 setData() - 修改对象类型数据
android·前端·小程序
用户32035783600239 分钟前
程序员鸡翅-Java微服务从0到1带你做社区项目实战
javascript
用户32035783600241 分钟前
高薪运维必备Prometheus监控系统企业级实战(已完结)
前端
一只爱打拳的程序猿44 分钟前
【SpringBoot】实现登录功能
javascript·css·spring boot·mybatis·html5
黄天才丶1 小时前
高级前端篇-脚手架开发
前端
乐闻x1 小时前
React 如何实现组件懒加载以及懒加载的底层机制
前端·react.js·性能优化·前端框架
小鱼冻干1 小时前
http模块
前端·node.js
悬炫1 小时前
闭包、作用域与作用域链:概念与应用
前端·javascript