Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rc-form

Package Overview
Dependencies
Maintainers
1
Versions
94
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rc-form - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

63

lib/createForm.js

@@ -62,3 +62,3 @@ 'use strict';

this.cachedBind = {};
var bindMethods = ['getFieldProps', 'isFieldValidating', 'getFieldError', 'removeField', 'validateFieldsByName', 'getFieldsValue'];
var bindMethods = ['getFieldProps', 'isFieldValidating', 'getFieldError', 'removeFields', 'validateFieldsByName', 'getFieldsValue', 'setFieldsValue'];
bindMethods.forEach(function (m) {

@@ -89,6 +89,6 @@ _this[m] = _this[m].bind(_this);

var field = this.getField(name, true);
this.setField(name, _extends({}, field, {
this.setFields(_defineProperty({}, name, _extends({}, field, {
value: value,
dirty: !!rules
}));
})));
}

@@ -141,3 +141,3 @@ }, {

var _fieldOption$initialValue = fieldOption.initialValue;
var initialValue = _fieldOption$initialValue === undefined ? '' : _fieldOption$initialValue;
var initialValue = _fieldOption$initialValue === undefined ? undefined : _fieldOption$initialValue;
var _fieldOption$validateTrigger = fieldOption.validateTrigger;

@@ -178,6 +178,6 @@ var validateTrigger = _fieldOption$validateTrigger === undefined ? 'onChange' : _fieldOption$validateTrigger;

key: 'getFieldsValue',
value: function getFieldsValue(fs) {
value: function getFieldsValue(names) {
var _this2 = this;
var fields = fs || Object.keys(this.state);
var fields = names || Object.keys(this.state);
var allValues = {};

@@ -206,6 +206,7 @@ fields.forEach(function (f) {

getFieldsValue: this.getFieldsValue,
setFieldsValue: this.setFieldsValue,
getFieldProps: this.getFieldProps,
getFieldError: this.getFieldError,
isFieldValidating: this.isFieldValidating,
removeField: this.removeField,
removeFields: this.removeFields,
validateFields: this.validateFieldsByName

@@ -215,14 +216,24 @@ };

}, {
key: 'setField',
value: function setField(name, field) {
var state = _defineProperty({}, name, field);
if (typeof name === 'object') {
state = name;
}
this.setState(state);
key: 'setFields',
value: function setFields(fields) {
this.setState(fields);
if (onFieldsChange) {
onFieldsChange(this.props, state);
onFieldsChange(this.props, fields);
}
}
}, {
key: 'setFieldsValue',
value: function setFieldsValue(fieldsValue) {
var fields = {};
for (var _name in fieldsValue) {
if (fieldsValue.hasOwnProperty(_name)) {
fields[_name] = {
name: _name,
value: fieldsValue[_name]
};
}
}
this.setFields(fields);
}
}, {
key: 'validateFields',

@@ -257,3 +268,3 @@ value: function validateFields(fields, callback, fieldNames) {

this.setField(allFields);
this.setFields(allFields);

@@ -300,3 +311,3 @@ if (callback && (0, _utils.isEmptyObject)(allFields)) {

});
_this3.setField(nowAllFields);
_this3.setFields(nowAllFields);
if (callback) {

@@ -346,8 +357,14 @@ callback((0, _utils.isEmptyObject)(errorsGroup) ? null : errorsGroup, _this3.getFieldsValue(fieldNames));

}, {
key: 'removeField',
value: function removeField(name) {
if (this.fieldsMeta[name]) {
delete this.fieldsMeta[name];
this.setField(name, undefined);
}
key: 'removeFields',
value: function removeFields(names) {
var _this5 = this;
var fields = {};
names.forEach(function (name) {
if (_this5.fieldsMeta[name]) {
delete _this5.fieldsMeta[name];
fields[name] = undefined;
}
});
this.setFields(fields);
}

@@ -354,0 +371,0 @@ }, {

{
"name": "rc-form",
"version": "0.2.0",
"version": "0.3.0",
"description": "React High Order Form Component",

@@ -41,2 +41,3 @@ "keywords": [

"devDependencies": {
"antd": "^0.10.4",
"expect.js": "0.3.x",

@@ -49,2 +50,3 @@ "pre-commit": "1.x",

"react-addons-test-utils": "0.14.x",
"react-data-binding": "^0.4.0",
"react-dom": "0.14.x",

@@ -51,0 +53,0 @@ "react-redux": "^4.0.0",

@@ -51,4 +51,5 @@ # rc-form

```js
import form from 'rc-form';
@form()
import { createForm } from 'rc-form';
@createForm()
class Form extends React.Component {

@@ -69,6 +70,14 @@ render() {

## API
## Function: createForm(formOption)
Call form() will return another function:
### formOption.onFieldsChange(props, fields)
Called when field changed, you can dispatch fields to redux store.
### formOption.mapPropsToFields(props)
convert value from props to fields. used for read fields from redux store.
createForm() will return another function:
### React.Component: function(WrappedComponent:React.Component)

@@ -100,2 +109,6 @@

### setFieldsValue(obj: Object)
set fields value by kv object.
### validateFields([fieldNames: String[]], callback: Function(errors, values))

@@ -102,0 +115,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc