Comparing version 1.2.0 to 1.3.0
# History | ||
---- | ||
## 1.3.0 / 2017-01-07 | ||
- support touch checking: https://github.com/react-component/form/pull/56 | ||
## 1.2.0 / 2017-01-05 | ||
@@ -4,0 +8,0 @@ |
@@ -95,3 +95,3 @@ 'use strict'; | ||
}, | ||
onCollectCommon: function onCollectCommon(name_, action, args, callback) { | ||
onCollectCommon: function onCollectCommon(name_, action, args) { | ||
var name = name_; | ||
@@ -115,7 +115,5 @@ var fieldMeta = this.getFieldMeta(name); | ||
var field = this.getField(name); | ||
callback({ name: name, field: field, fieldMeta: fieldMeta, value: value }); | ||
return { name: name, field: (0, _extends3["default"])({}, field, { value: value, touched: true }), fieldMeta: fieldMeta }; | ||
}, | ||
onCollect: function onCollect(name_, action) { | ||
var _this = this; | ||
for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { | ||
@@ -125,19 +123,15 @@ args[_key - 2] = arguments[_key]; | ||
this.onCollectCommon(name_, action, args, function (_ref) { | ||
var name = _ref.name, | ||
field = _ref.field, | ||
fieldMeta = _ref.fieldMeta, | ||
value = _ref.value; | ||
var validate = fieldMeta.validate; | ||
var _onCollectCommon = this.onCollectCommon(name_, action, args), | ||
name = _onCollectCommon.name, | ||
field = _onCollectCommon.field, | ||
fieldMeta = _onCollectCommon.fieldMeta; | ||
var fieldContent = (0, _extends3["default"])({}, field, { | ||
value: value, | ||
dirty: (0, _utils.hasRules)(validate) | ||
}); | ||
_this.setFields((0, _defineProperty3["default"])({}, name, fieldContent)); | ||
var validate = fieldMeta.validate; | ||
var fieldContent = (0, _extends3["default"])({}, field, { | ||
dirty: (0, _utils.hasRules)(validate) | ||
}); | ||
this.setFields((0, _defineProperty3["default"])({}, name, fieldContent)); | ||
}, | ||
onCollectValidate: function onCollectValidate(name_, action) { | ||
var _this2 = this; | ||
for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) { | ||
@@ -147,18 +141,15 @@ args[_key2 - 2] = arguments[_key2]; | ||
this.onCollectCommon(name_, action, args, function (_ref2) { | ||
var field = _ref2.field, | ||
fieldMeta = _ref2.fieldMeta, | ||
value = _ref2.value; | ||
var _onCollectCommon2 = this.onCollectCommon(name_, action, args), | ||
field = _onCollectCommon2.field, | ||
fieldMeta = _onCollectCommon2.fieldMeta; | ||
var fieldContent = (0, _extends3["default"])({}, field, { | ||
value: value, | ||
dirty: true | ||
}); | ||
_this2.validateFieldsInternal([fieldContent], { | ||
action: action, | ||
options: { | ||
firstFields: !!fieldMeta.validateFirst | ||
} | ||
}); | ||
var fieldContent = (0, _extends3["default"])({}, field, { | ||
dirty: true | ||
}); | ||
this.validateFieldsInternal([fieldContent], { | ||
action: action, | ||
options: { | ||
firstFields: !!fieldMeta.validateFirst | ||
} | ||
}); | ||
}, | ||
@@ -183,7 +174,7 @@ getCacheBind: function getCacheBind(name, action, fn) { | ||
getFieldDecorator: function getFieldDecorator(name, fieldOption) { | ||
var _this3 = this; | ||
var _this = this; | ||
var props = this.getFieldProps(name, fieldOption); | ||
return function (fieldElem) { | ||
var fieldMeta = _this3.getFieldMeta(name); | ||
var fieldMeta = _this.getFieldMeta(name); | ||
var originalProps = fieldElem.props; | ||
@@ -198,7 +189,7 @@ if (process.env.NODE_ENV !== 'production') { | ||
fieldMeta.ref = fieldElem.ref; | ||
return _react2["default"].cloneElement(fieldElem, (0, _extends3["default"])({}, props, _this3.getFieldValuePropValue(fieldMeta))); | ||
return _react2["default"].cloneElement(fieldElem, (0, _extends3["default"])({}, props, _this.getFieldValuePropValue(fieldMeta))); | ||
}; | ||
}, | ||
getFieldProps: function getFieldProps(name) { | ||
var _this4 = this; | ||
var _this2 = this; | ||
@@ -262,3 +253,3 @@ var usersFieldOption = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
if (inputProps[action]) return; | ||
inputProps[action] = _this4.getCacheBind(name, action, _this4.onCollectValidate); | ||
inputProps[action] = _this2.getCacheBind(name, action, _this2.onCollectValidate); | ||
}); | ||
@@ -306,2 +297,12 @@ | ||
}, | ||
getFieldsError: function getFieldsError(names) { | ||
var _this3 = this; | ||
var fields = names || (0, _utils.flatFieldNames)(this.getValidFieldsName()); | ||
var allErrors = {}; | ||
fields.forEach(function (f) { | ||
(0, _lodash6["default"])(allErrors, f, _this3.getFieldError(f)); | ||
}); | ||
return allErrors; | ||
}, | ||
getFieldError: function getFieldError(name) { | ||
@@ -317,3 +318,3 @@ return (0, _utils.getErrorStrs)(this.getFieldMember(name, 'errors')); | ||
getFieldsValue: function getFieldsValue(names) { | ||
var _this5 = this; | ||
var _this4 = this; | ||
@@ -323,3 +324,3 @@ var fields = names || (0, _utils.flatFieldNames)(this.getValidFieldsName()); | ||
fields.forEach(function (f) { | ||
(0, _lodash6["default"])(allValues, f, _this5.getFieldValue(f)); | ||
(0, _lodash6["default"])(allValues, f, _this4.getFieldValue(f)); | ||
}); | ||
@@ -345,3 +346,3 @@ return allValues; | ||
getValueFromFields: function getValueFromFields(name, fields) { | ||
var _this6 = this; | ||
var _this5 = this; | ||
@@ -356,3 +357,3 @@ var fieldsMeta = this.fieldsMeta; | ||
if (nameIfNested.name === name && nameIfNested.isNested) { | ||
(0, _lodash6["default"])(ret, fieldKey, _this6.getValueFromFieldsInternal(fieldKey, fields)); | ||
(0, _lodash6["default"])(ret, fieldKey, _this5.getValueFromFieldsInternal(fieldKey, fields)); | ||
} | ||
@@ -378,3 +379,3 @@ }); | ||
setFields: function setFields(fields_) { | ||
var _this7 = this; | ||
var _this6 = this; | ||
@@ -393,3 +394,3 @@ var fieldsMeta = this.fieldsMeta; | ||
} | ||
nowValues[f] = _this7.getValueFromFields(f, nowFields); | ||
nowValues[f] = _this6.getValueFromFields(f, nowFields); | ||
}); | ||
@@ -400,3 +401,3 @@ Object.keys(nowValues).forEach(function (f) { | ||
if (fieldMeta && fieldMeta.normalize) { | ||
var nowValue = fieldMeta.normalize(value, _this7.getValueFromFields(f, _this7.fields), nowValues); | ||
var nowValue = fieldMeta.normalize(value, _this6.getValueFromFields(f, _this6.fields), nowValues); | ||
if (nowValue !== value) { | ||
@@ -415,5 +416,5 @@ nowFields[f] = (0, _extends3["default"])({}, nowFields[f], { | ||
changedFieldsName.forEach(function (f) { | ||
changedFields[f] = _this7.getField(f); | ||
changedFields[f] = _this6.getField(f); | ||
}); | ||
onFieldsChange(_this7.props, changedFields); | ||
onFieldsChange(_this6.props, changedFields); | ||
})(); | ||
@@ -495,9 +496,9 @@ } | ||
}, | ||
validateFieldsInternal: function validateFieldsInternal(fields, _ref4, callback) { | ||
var _this8 = this; | ||
validateFieldsInternal: function validateFieldsInternal(fields, _ref2, callback) { | ||
var _this7 = this; | ||
var fieldNames = _ref4.fieldNames, | ||
action = _ref4.action, | ||
_ref4$options = _ref4.options, | ||
options = _ref4$options === undefined ? {} : _ref4$options; | ||
var fieldNames = _ref2.fieldNames, | ||
action = _ref2.action, | ||
_ref2$options = _ref2.options, | ||
options = _ref2$options === undefined ? {} : _ref2$options; | ||
@@ -516,3 +517,3 @@ var allRules = {}; | ||
} | ||
var fieldMeta = _this8.getFieldMeta(name); | ||
var fieldMeta = _this7.getFieldMeta(name); | ||
var newField = (0, _extends3["default"])({}, field); | ||
@@ -522,3 +523,3 @@ newField.errors = undefined; | ||
newField.dirty = true; | ||
allRules[name] = _this8.getRules(fieldMeta, action); | ||
allRules[name] = _this7.getRules(fieldMeta, action); | ||
allValues[name] = newField.value; | ||
@@ -530,3 +531,3 @@ allFields[name] = newField; | ||
Object.keys(allValues).forEach(function (f) { | ||
allValues[f] = _this8.getFieldValue(f); | ||
allValues[f] = _this7.getFieldValue(f); | ||
}); | ||
@@ -557,3 +558,3 @@ if (callback && (0, _utils.isEmptyObject)(allFields)) { | ||
var fieldErrors = (0, _lodash2["default"])(errorsGroup, name); | ||
var nowField = _this8.getField(name); | ||
var nowField = _this7.getField(name); | ||
// avoid concurrency problems | ||
@@ -572,7 +573,7 @@ if (nowField.value !== allValues[name]) { | ||
}); | ||
_this8.setFields(nowAllFields); | ||
_this7.setFields(nowAllFields); | ||
if (callback) { | ||
if (expired.length) { | ||
expired.forEach(function (_ref5) { | ||
var name = _ref5.name; | ||
expired.forEach(function (_ref3) { | ||
var name = _ref3.name; | ||
@@ -590,3 +591,3 @@ var fieldErrors = [{ | ||
callback((0, _utils.isEmptyObject)(errorsGroup) ? null : errorsGroup, _this8.getFieldsValue((0, _utils.flatFieldNames)(fieldNames))); | ||
callback((0, _utils.isEmptyObject)(errorsGroup) ? null : errorsGroup, _this7.getFieldsValue((0, _utils.flatFieldNames)(fieldNames))); | ||
} | ||
@@ -596,3 +597,3 @@ }); | ||
validateFields: function validateFields(ns, opt, cb) { | ||
var _this9 = this; | ||
var _this8 = this; | ||
@@ -606,7 +607,7 @@ var _getParams = (0, _utils.getParams)(ns, opt, cb), | ||
var fields = fieldNames.filter(function (name) { | ||
var fieldMeta = _this9.getFieldMeta(name); | ||
var fieldMeta = _this8.getFieldMeta(name); | ||
return (0, _utils.hasRules)(fieldMeta.validate); | ||
}).map(function (name) { | ||
var field = _this9.getField(name); | ||
field.value = _this9.getFieldValue(name); | ||
var field = _this8.getField(name); | ||
field.value = _this8.getFieldValue(name); | ||
return field; | ||
@@ -622,3 +623,3 @@ }); | ||
options.firstFields = fieldNames.filter(function (name) { | ||
var fieldMeta = _this9.getFieldMeta(name); | ||
var fieldMeta = _this8.getFieldMeta(name); | ||
return !!fieldMeta.validateFirst; | ||
@@ -636,2 +637,13 @@ }); | ||
isFieldsValidating: function isFieldsValidating(ns) { | ||
var _this9 = this; | ||
var names = ns || this.getValidFieldsName(); | ||
return names.some(function (n) { | ||
return _this9.isFieldValidating(n); | ||
}); | ||
}, | ||
isFieldTouched: function isFieldTouched(name) { | ||
return this.getFieldMember(name, 'touched'); | ||
}, | ||
isFieldsTouched: function isFieldsTouched(ns) { | ||
var _this10 = this; | ||
@@ -641,3 +653,3 @@ | ||
return names.some(function (n) { | ||
return _this10.isFieldValidating(n); | ||
return _this10.isFieldTouched(n); | ||
}); | ||
@@ -644,0 +656,0 @@ }, |
@@ -25,5 +25,8 @@ 'use strict'; | ||
getFieldProps: this.getFieldProps, | ||
getFieldsError: this.getFieldsError, | ||
getFieldError: this.getFieldError, | ||
isFieldValidating: this.isFieldValidating, | ||
isFieldsValidating: this.isFieldsValidating, | ||
isFieldsTouched: this.isFieldsTouched, | ||
isFieldTouched: this.isFieldTouched, | ||
isSubmitting: this.isSubmitting, | ||
@@ -30,0 +33,0 @@ submit: this.submit, |
{ | ||
"name": "rc-form", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "React High Order Form Component", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -288,2 +288,6 @@ # rc-form | ||
### getFieldsError(names): Object{ [name]: String[] } | ||
Get inputs' validate errors. | ||
### getFieldError(name): String[] | ||
@@ -301,2 +305,10 @@ | ||
### isFieldTouched(name: String): Bool | ||
Whether this input's value had been change. | ||
### isFieldsTouched(names: String[]): Bool | ||
Whether one of the inputs' values had been change. | ||
### isSubmitting(): Bool | ||
@@ -303,0 +315,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1285203
8444
384