npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

antd-form-plus

v0.1.9

Published

简化了一些 antd form 的开发,在兼容 antd form 的同时进行了一些增强

Downloads

5

Readme

antd-form-plus

简化了一些 antd form 的开发,在兼容 antd form 的同时进行了一些增强

Installation

npm install --save antd-form-plus

Usage

支持根据定义好的 fields 进行渲染

定义 fields

  • fields 中支持 FormItem 和 getFieldDecorator 的全部属性和参数,具体参数可以参考官方文档:https://ant.design/components/form-cn/#getFieldDecorator(id,-options)
  • fields 中支持 errors,可以在初始是直接显示表单项的错误信息,再后面的验证后可以被覆盖
  • fields 简化了 mapPropsToFields 的操作,无需通过 Form.createFormField() 对数据进行处理
  • fields 支持 props 属性,可以为 FormField 中的表单项组件设置属性,但优先级比表单项组件标签上的属性低
  • fields 支持 props 属性不建议设置 value 和 onChange,否则会收到 antd form 的 getFieldDecorator 的无情警告
class demo {
    fields = {
            title: {
                value: '标题的初始值',
                label: intl.formatMessage({id: 'form.title.label'}),
                rules: [
                    {
                        required: true,
                        message: intl.formatMessage({id: 'validation.title.required'}),
                    },
                ],
                errors: [
                    {
                        message: '初始显示的错误信息'
                    }
                ],
                // 不要绑定 value 和 onChange 事件
                props: {
                    placeholder: '给目标起个名称吧'
                }
            },
            date: {
                value: [
                    moment('2019-01-01'),
                    moment('2019-03-01')
                ],
                label: intl.formatMessage({id: 'form.date.label'}),
                rules: [
                    {
                        required: true,
                        message: intl.formatMessage({id: 'validation.date.required'}),
                    }
                ]
            }
    }
}
  • Form.create() 新增了 fields 参数,类似 mapPropsToFields 的方式从 redux 或 mobx 中获取到 store
  • Form.create() 参数中 存在 mapPropsToFields 而不存在 fields 时,会自动根据 mapPropsToFields 的值转化为 fields
  • 使用 FormField 替换了 getFieldDecorator(),会在 FormField 中根据其 field 属性去调用 getFieldDecorator 进行渲染
  • FormItem 如果定义了 field={form.get(XXX)},则会根据定义的属性进行渲染,但同时也支持在 FormItem 标签内直接定义属性,并且标签内的属性优先级最高
  • FormField 必须指定属性 field={form.get('title')},组件内部会调用 getFieldDecorator()
  • form.get('XXX') 会返回 {form: form, name: 'XXX'} 格式的对象,建议使用 form.get('XXX')
  • FormField 中必须并且有仅能有一个表单项,与 getFieldDecorator 的要求一致
import {Form} from 'antd-form-plus'

const FormItem = Form.Item;
const FormField = Form.Field;

@Form.create({
    fields: ({demo}) => demo.fields
})
class BasicForms extends React.Component {
    
    handleSubmit = e => {
        const {dispatch, form} = this.props;
        e.preventDefault();
        form.validateFieldsAndScroll((err, values) => {
            if (!err) {
                // submit form
            }
        });
    };
    
    render(){
        
        const {form} = this.props;
        
        return (
            <Form onSubmit={this.handleSubmit} hideRequiredMark style={{marginTop: 8}}>
                <FormItem field={form.get('title')}>
                    <FormField field={form.get('title')} label='我的优先级更高'>
                        <Input placeholder='请输入标题'/>
                    </FormField>
                </FormItem>
                <FormItem field={form.get('date')}>
                    <FormField field={form.get('date')} rules={[{required: true, message: '我的优先级更高'}]}>
                        <RangePicker
                            style={{width: '100%'}}
                            placeholder={[
                                formatMessage({id: 'form.date.placeholder.start'}),
                                formatMessage({id: 'form.date.placeholder.end'}),
                            ]}
                        />
                    </FormField>
                </FormItem>
                <FormItem style={{marginTop: 32}}>
                    <Button type="primary" htmlType="submit">
                        <FormattedMessage id="form.submit"/>
                    </Button>
                    <Button style={{marginLeft: 8}}>
                        <FormattedMessage id="form.save"/>
                    </Button>                                            
                </FormItem>
            </Form>
        );
    }
}

License

MIT Copyright (c) 2019