antd - 表单校验组件demo

import React, { Component } from 'react';
import { Form, Input,Select } from "antd";
const {Option} = Select;
class ModelForm extends Component {

    render() {
    	//外部传过来的数据
    	console.log(this.props.modelData)
    	//将里边的数据进行解构出来
    	let {aaa,bbb,ccc} = this.props.modelData
        const { getFieldDecorator } = this.props.form;
        const formItemLayout = {
            labelCol: {
                xs: { span: 4 },

            },
            wrapperCol: {
                xs: { span: 20 },

            },
        };
        return (
            <Form {...formItemLayout}>
                <Form.Item label="用户id">
                    {                   
                        getFieldDecorator("booksName", {
                            rules: [
                                {
                                    required:true,
                                    message:"不能为空"
                                }
                            ]
                        })(
                            <Input />
                        )
                    }
                </Form.Item>
                <Form.Item label="用户名称">
                    {
                        getFieldDecorator("username", {
                            rules: [],
                            //与rules同级设置默认值
                            initialValue:aaa
                        	
                        })(
                            <Input />
                        )
                    }
                </Form.Item>
                <Form.Item label="用户信息">
                    {
                        getFieldDecorator("username", {
                            rules: [],
                            //与rules同级设置默认值
                            initialValue:bbb
                        })(
                            <Input />
                        )
                    }
                </Form.Item>
                <Form.Item label="用户状态">
                    {
                        getFieldDecorator("username", {
                            rules: [],
                             //与rules同级设置默认值
                            initialValue:ccc
                        })(
                            <Select>
                                <Option value="出勤">出勤</Option>
                                <Option value="请假">请假</Option>
                                <Option value="旷工">旷工</Option>
                            </Select>
                        )
                    }
                </Form.Item>
                <Form.Item label="用户时间">
                    {
                        getFieldDecorator("username", {
                            rules: []
                        })(
                            <Input />
                        )
                    }
                </Form.Item>
            </Form>
        )
    }
}

export default Form.create()(ModelForm)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值