wrap-component-with-valour
Advanced tools
Comparing version 1.2.0 to 2.0.0
@@ -25,2 +25,10 @@ 'use strict'; | ||
var _lodash3 = require('lodash.isequal'); | ||
var _lodash4 = _interopRequireDefault(_lodash3); | ||
var _lodash5 = require('lodash.first'); | ||
var _lodash6 = _interopRequireDefault(_lodash5); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -49,2 +57,3 @@ | ||
_this.setValidationStateForValue = _this.setValidationStateForValue.bind(_this); | ||
_this.setValidationResult = _this.setValidationResult.bind(_this); | ||
return _this; | ||
@@ -61,3 +70,14 @@ } | ||
value: function componentDidMount() { | ||
var _this2 = this; | ||
this.setValidationStateForValue(this.props.valueName, this.props.value); | ||
_valour2.default.onUpdated(this.props.formName, function (results) { | ||
var value = _this2.state.value; | ||
var valueName = _this2.props.valueName; | ||
var result = results[valueName]; | ||
_this2.setValidationResult(result, value); | ||
}); | ||
} | ||
@@ -70,16 +90,21 @@ }, { | ||
}, { | ||
key: 'setValidationStateForValue', | ||
value: function setValidationStateForValue(valueName, value) { | ||
key: 'setValidationResult', | ||
value: function setValidationResult(result, value) { | ||
var _props = this.props, | ||
formName = _props.formName, | ||
onValidationStateChanged = _props.onValidationStateChanged; | ||
valueName = _props.valueName, | ||
onValidationStateChanged = _props.onValidationStateChanged, | ||
forceRevalidation = _props.forceRevalidation; | ||
var _state = this.state, | ||
previousValidationResult = _state.previousValidationResult, | ||
oldValue = _state.value; | ||
_valour2.default.runValidationSync(formName, _defineProperty({}, '' + valueName, value)); | ||
if ((0, _lodash4.default)(previousValidationResult, result) && value === oldValue && !forceRevalidation) { | ||
return; | ||
} | ||
var validationResult = _valour2.default.getResult(formName)[valueName]; | ||
var isValid = validationResult.valid !== undefined ? validationResult.valid : false; | ||
var message = validationResult.messages !== undefined ? validationResult.messages[0] : null; | ||
var newState = { isValid: isValid, message: message }; | ||
this.setState(newState, function () { | ||
var isValid = result.isValid || false; | ||
var message = (0, _lodash6.default)(result.messages) || null; | ||
var nextState = { isValid: isValid, message: message, value: value, previousValidationResult: result }; | ||
this.setState(nextState, function () { | ||
return onValidationStateChanged(valueName, value, isValid, message); | ||
@@ -89,2 +114,13 @@ }); | ||
}, { | ||
key: 'setValidationStateForValue', | ||
value: function setValidationStateForValue(valueName, value) { | ||
var formName = this.props.formName; | ||
_valour2.default.runValidationSync(formName, _defineProperty({}, valueName, value)); | ||
var validationResult = _valour2.default.getResult(formName)[valueName]; | ||
this.setValidationResult(validationResult, value); | ||
} | ||
}, { | ||
key: 'render', | ||
@@ -114,7 +150,9 @@ value: function render() { | ||
onValidationStateChanged: _react2.default.PropTypes.func, | ||
shouldRenderValidationState: _react2.default.PropTypes.bool | ||
shouldRenderValidationState: _react2.default.PropTypes.bool, | ||
forceRevalidation: _react2.default.PropTypes.bool | ||
}, _class.defaultProps = { | ||
onValidationStateChanged: _lodash2.default, | ||
shouldRenderValidationState: true | ||
shouldRenderValidationState: true, | ||
forceRevalidation: false | ||
}, _temp; | ||
} |
{ | ||
"name": "wrap-component-with-valour", | ||
"version": "1.2.0", | ||
"version": "2.0.0", | ||
"description": "Wrap a component with client side validation functionality using the Valour library", | ||
@@ -22,2 +22,4 @@ "main": "lib/wrap-component-with-valour.js", | ||
"dependencies": { | ||
"lodash.first": "^3.0.0", | ||
"lodash.isequal": "^4.5.0", | ||
"lodash.noop": "^3.0.1" | ||
@@ -24,0 +26,0 @@ }, |
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
11348
116
5
+ Addedlodash.first@^3.0.0
+ Addedlodash.isequal@^4.5.0
+ Addedlodash.first@3.0.0(transitive)
+ Addedlodash.isequal@4.5.0(transitive)