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-redux

v3.0.28

Published

connect antd Form to redux with one API. compare to redux-form

Downloads

18

Readme

Connect antd Form to redux

Install

npm install antd-form-redux --save

Usage

Connect antd Form to redux use "reduxForm" HOC. If you are familiar with redux-form, you will find it very the same. If you are new to Form and redux, it is also very simple since it just use one API.

You just need 2 steps:

Step-1. add reducer to your reducers

import { combineReducers } from 'redux';
import { reducer as formReducer } from 'antd-form-redux';

//import other reducers
const rootReducer = combineReducers({
  ...reducers,
  form: formReducer,
});

Step-2. Use reduxForm(config) to connect component

import { reduxForm } from 'antd-form-redux';

class NormalAntdForm extend Compoent {
  // ...
  render() {
    // ...
    const { test } = this.props;
    const { getFieldDecorator } = this.props.form;
    // use antd's pattern :
    // getFieldDecorator('fileds', .....)
    // ...
  }
}

export default reduxForm({
  form: 'test',  //the name of the form data store
})(NormalAntdForm);

Note: you should also use the antd getFieldDecorator to do field bind and value check there is no support like redux-form's Field or validate.

Configure options:

This project make effort to use antd likes redux-form, these are supported configures now:

form : String [required]

Object<String, String> [optional]

enableReinitialize : boolean [optional]

keepDirtyOnReinitialize : boolean [optional]

destroyOnUnmount : boolean [optional]

forceUnregisterOnUnmount : boolean [optional]

getFormState : Function [optional]

onChange : Function [optional]

  • values : Object
  • dispatch : Function
  • props : Object
  • previousValues : Object

immutableProps : Array [optional]

onSubmitFail : Function

  • errors : Object
  • dispatch : Function
  • submitError : Error
  • props : Object

onSubmitSuccess : Function [optional]

  • result : Object
  • dispatch : Function
  • props : Object

onSubmit : Function

  • values : Object
  • dispatch : Function
  • props : Object

Action creators

There is also supplied redux-form likes action creators:

initialize(form, data)

data : { fields, ....} use fields to set initialValues, you donnot use this action usually

destroy(...forms)

delete the form data from store you donnot use this action usually

change(form, fields)

change the form fields values

startSubmit(form)

set submitting to true

stopSubmit(form, errors)

set submitting to false

setSubmitSucceeded(form)

set submitFailed to false

setSubmitFailed(form)

set submitFailed to true

clearSubmitErrors(form)

delete all errors

Note: if you want to get/set the submitting state, server validate errors to the form reducer, you would dispatch actions on your own, this is usually done in side effect handlers, such as rudux-thunk, redux-promise, redux-saga, redux-observable, etc.

Props

The props listed here are the props that generated to give to your decorated form component.

reset : Function

reset the form values to initialValues

initialize : Function(values)

initialize the form values to values

Example

this is a example according to antd docs:

import React, {Component} from 'react'
import { reduxForm } from 'antd-form-redux';
import { Form, Icon, Input, Button, Checkbox } from 'antd';
const FormItem = Form.Item;

class NormalLoginForm extends React.Component {
  render() {
    const {login} = this.props;
    const { getFieldDecorator } = this.props.form;
    return (
      <Form onSubmit={this.handleSubmit} className="login-form">
        <FormItem>
          {getFieldDecorator('userName', {
            rules: [{ required: true, message: 'Please input your username!' }],
          })(
            <Input prefix={<Icon type="user" style={{ fontSize: 13 }} />} placeholder="Username" />
          )}
        </FormItem>
        <FormItem>
          {getFieldDecorator('password', {
            rules: [{ required: true, message: 'Please input your Password!' }],
          })(
            <Input prefix={<Icon type="lock" style={{ fontSize: 13 }} />} type="password" placeholder="Password" />
          )}
        </FormItem>
        <FormItem>
          {getFieldDecorator('remember', {
            valuePropName: 'checked',
            initialValue: true,
          })(
            <Checkbox>Remember me</Checkbox>
          )}
          <a className="login-form-forgot" href="">Forgot password</a>
          <Button
            type="primary"
            htmlType="submit"
            className="login-form-button"
            disabled={login.submitting}
          >
            Log in
          </Button>
          Or <a href="">register now!</a>
        </FormItem>
      </Form>
    );
  }
}

const WrappedNormalLoginForm = reduxForm({
  form: 'login',  //the name of the form data store
  onSubmit: function(values, dispatch, props) {
      //do with values, dispatch , props
      console.log('Received values of form: ', values);
  }
})(NormalLoginForm);

Note: you can also give onSubmit as props from parent Component.