@36node/redux-form-antd
A higher order component decorator form using @36node/redux-form and antd form
Last updated a year ago by zzswang .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @36node/redux-form-antd 
SYNC missed versions from official npm registry.

Redex Form Antd

version downloads

A HOC for antd form, to connect @36node/redux-form

Install

$ yarn install @36node/redux-form

Use

import React, { PureComponent } from "react";
import createForm from "@36node/redux-form-antd";

@createForm("SAMPLE_FORM")
class MyForm extends PureComponent {
  render() {
    // do not use form.getFieldDecorator
    const { getFieldDecorator } = this.props;
    const formItemLayout = {
      labelCol: { span: 6 },
      wrapperCol: { span: 14 },
    };

    const tailFormItemLayout = {
      wrapperCol: {
        xs: {
          span: 24,
          offset: 6,
        },
        sm: {
          span: 16,
          offset: 6,
        },
      },
    };

    return (
      <Form {...formItemLayout} onSubmit={this.handleSubmit}>
        <Form.Item label="Select" hasFeedback>
          {getFieldDecorator("select", {
            initialValue: "china",
            rules: [{ required: true, message: "Please select your country!" }],
          })(
            <Select placeholder="Please select a country">
              <Option value="china">China</Option>
              <Option value="usa">U.S.A</Option>
            </Select>
          )}
        </Form.Item>

        <Form.Item label="Select[multiple]">
          {getFieldDecorator("select-multiple", {
            rules: [
              {
                required: true,
                message: "Please select your favourite colors!",
                type: "array",
              },
            ],
          })(
            <Select
              mode="multiple"
              placeholder="Please select favourite colors"
            >
              <Option value="red">Red</Option>
              <Option value="green">Green</Option>
              <Option value="blue">Blue</Option>
            </Select>
          )}
        </Form.Item>

        <Form.Item label="InputNumber">
          {getFieldDecorator("input-number", { initialValue: 3 })(
            <InputNumber min={1} max={10} />
          )}
          <span className="ant-form-text"> machines</span>
        </Form.Item>

        <Form.Item label="Switch">
          {getFieldDecorator("switch", { valuePropName: "checked" })(
            <Switch />
          )}
        </Form.Item>

        <Form.Item label="Slider">
          {getFieldDecorator("slider")(
            <Slider
              marks={{
                0: "A",
                20: "B",
                40: "C",
                60: "D",
                80: "E",
                100: "F",
              }}
            />
          )}
        </Form.Item>

        <Form.Item label="Radio.Group">
          {getFieldDecorator("radio-group")(
            <Radio.Group>
              <Radio value="a">item 1</Radio>
              <Radio value="b">item 2</Radio>
              <Radio value="c">item 3</Radio>
            </Radio.Group>
          )}
        </Form.Item>

        <Form.Item {...tailFormItemLayout}>
          <Button type="primary" htmlType="submit">
            Submit
          </Button>

          <Button
            onClick={() => {
              this.handleReset();
            }}
            style={{ marginLeft: 8 }}
            type="danger"
            ghost
          >
            Reset
          </Button>

          <Button
            style={{ marginLeft: 8 }}
            onClick={() => {
              this.handleReset({
                select: "usa",
                "radio-group": "c",
                switch: true,
                slider: 60,
                "number-input": 4,
                "select-multiple": ["red"],
              });
            }}
            type="danger"
          >
            Reset(with initial value)
          </Button>
        </Form.Item>
      </Form>
    );
  }

  handleSubmit = e => {
    e.preventDefault();

    this.props.form.validateFieldsAndScroll((err, values) => {
      if (!err) {
        console.log("Received values of form: ", values);
      }
    });
  };

  handleReset = initialValues => {
    this.props.reset(initialValues);
  };
}

Api

import {
  WrappedFormInternalProps,
  GetFieldDecoratorOptions,
} from "antd/lib/form/Form";

import { FieldState, Fields } from "@36node/redux-form";
import { DispatchProp } from "react-redux";

export interface ReduxFormAntdProps
  extends WrappedFormInternalProps,
    DispatchProp {
  // overwrite antd.Form.getFieldDecorator
  getFieldDecorator: (
    id: String,
    options: GetFieldDecoratorOptions
  ) => (node: React.ReactNode) => React.ReactNode;
  // reset form with initial values
  reset: (initialValues: Object) => void;
  // change form field value by name
  changeField: (fieldName: String, field: FieldState) => void;
  // fields
  fields: Fields;
}

Current Tags

  • 0.0.24                                ...           latest (a year ago)

24 Versions

  • 0.0.24                                ...           a year ago
  • 0.0.23                                ...           a year ago
  • 0.0.22                                ...           a year ago
  • 0.0.21                                ...           a year ago
  • 0.0.20                                ...           a year ago
  • 0.0.19                                ...           a year ago
  • 0.0.18                                ...           a year ago
  • 0.0.17                                ...           a year ago
  • 0.0.16                                ...           a year ago
  • 0.0.15                                ...           a year ago
  • 0.0.14                                ...           a year ago
  • 0.0.13                                ...           a year ago
  • 0.0.12                                ...           a year ago
  • 0.0.11                                ...           a year ago
  • 0.0.10                                ...           a year ago
  • 0.0.9                                ...           a year ago
  • 0.0.8                                ...           a year ago
  • 0.0.7                                ...           a year ago
  • 0.0.6                                ...           a year ago
  • 0.0.5                                ...           a year ago
  • 0.0.4                                ...           a year ago
  • 0.0.3                                ...           a year ago
  • 0.0.2                                ...           a year ago
  • 0.0.1                                ...           a year ago
Downloads
Today 0
This Week 24
This Month 24
Last Day 0
Last Week 0
Last Month 70
Dependencies (4)
Dev Dependencies (8)

Copyright 2014 - 2016 © taobao.org |