
Security News
Risky Biz Podcast: AI Agents Are Raising the Stakes for Software Supply Chain Security
Open source attacks are accelerating as AI coding agents pull in dependencies faster, with less human review.
ant-modifier
Advanced tools
如果你受够了 AntDesign 的原生 Form,那就来试试它吧!一款更懂你的表单提交组件
目前功能:
计划实现:
npm install ant-modifier
git clone https://github.com/aweiu/ant-modifier.git
yarn install
yarn run start
react >= 16.3.0 webpack es6 开发环境
建议配合 TypeScript 食用!调试本项目你得到的就是一份同时支持 js 和 ts 的工程,所以你可以基于它去改造你的现有项目
简化 AntForm 的使用:你不需要写Form.create 和 getFieldDecorator了!同时提供 Modifier 的表单提交功能
如下示例:
import * as React from 'react'
import * as Modifier from 'Modifier'
import { Input, Button } from 'antd'
function submit(formData, customData) {
console.log(formData, customData)
return new Promise((resolve) => setTimeout(resolve, 1000))
}
function onSubmit() {
Modifier.Form.submit('modifierForm', 'customData')
}
function App() {
return (
<Modifier.Form name="modifierForm" action={submit}>
<Modifier.Item id="name" rules={[{ required: true }]}>
<Input placeholder="请输入用户名" />
</Modifier.Item>
<Button onClick={onSubmit}>提交</Button>
</Modifier.Form>
)
}
可以理解为组件的 id,有了它你才可以方便地调用到组件实例的各种方法
拿到表单数据之后你要做什么?比如表单的数据提交过程应当交给它
如果你需要用到 Form.create 的某些特性,直接:
<Modifier.Form mapPropsToFields={ mapPropsToFields } onFieldsChange={ onFieldsChange } />
等同于:
Form.create({ mapPropsToFields, onFieldsChange })
组件代理了 AntForm 的所有 props,可参考上面链接
组件的静态方法,调用它会执行数据提交前的一些准备工作,如表单校验。完成后会执行 action
如果你业务中表单的修改和创建是在弹窗中完成的,那就来用它吧!除了提供简化 AntForm 的功能外,还为你自动管理了 Modal 的状态
如下示例:
import * as React from 'react'
import * as Modifier from 'Modifier'
import { Input, Button } from 'antd'
function submit(formData, customData) {
console.log(formData, customData)
return new Promise((resolve) => setTimeout(resolve, 1000))
}
function onSubmit() {
Modifier.Modal.show('modifierModal', 'customData')
}
function App() {
return (
<div>
<Modifier.Modal name="modifierModal" action={submit} title="创建用户">
<Form>
<Modifier.Item id="name" rules={[{ required: true }]}>
<Input placeholder="请输入用户名" />
</Modifier.Item>
</Form>
</Modifier.Modal>
<Button onClick={onSubmit}>创建用户</Button>
</div>
)
}
可以看到你唯一需要做的就是在需要它出现的时候去调用 Modifier.Modal.show
同 Form.props.AntFormCreateOption
visibleconfirmLoadingonOkonCancel除了以上属性被「征用」了,组件代理了 AntModal 的所有 props,可参考上面链接
组件的静态方法,调用它会使你的弹窗表单变成可见状态,之后的行为同 Form.submit 一致;关闭和 loading 状态由它自己维护
功能类似于 AntFormItem
getFieldDecorator 的 id 参数
getFieldDecorator 的 options 参数
<Modifier.Item id="name" rules={ [ { required: true } ] } initialValue="Jack" >
<Input />
</Modifier.Item>
等同于:
<Form.Item>
{
getFieldDecorator('name', { rules: [ { required: true } ], initialValue: 'Jack' })(<Input />)
}
</Form.Item>
Modifier、Modal、Form 共享的静态方法,用于获取某个 Modifier 实例 的 props.form
name) => WrappedFormUtils | undefinedimport * as Modifier from 'Modifier'
const form = Modifier.getForm('userCreator')
// const form = Modifier.Modal.getForm('userCreator')
// const form = Modifier.Form.getForm('userCreator')
if (form) {
console.log(form.getFieldsValue()) // https://github.com/ant-design/ant-design/blob/master/components/form/Form.tsx#L140
}
FAQs
如果你受够了 AntDesign 的原生 Form,那就来试试它吧!一款更懂你的表单提交组件
The npm package ant-modifier receives a total of 30 weekly downloads. As such, ant-modifier popularity was classified as not popular.
We found that ant-modifier demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Open source attacks are accelerating as AI coding agents pull in dependencies faster, with less human review.

Research
/Security News
Malicious Chrome and Firefox extensions posed as free VPNs while stealing clipboard data through later extension updates.

Research
/Security News
Miasma Mini Shai-Hulud hits @immobiliarelabs Backstage plugins, targeting GitLab and LDAP auth packages on npm.