calidation
Advanced tools
Comparing version 1.6.2 to 1.7.0
@@ -84,4 +84,24 @@ 'use strict'; | ||
_this.setState({ errors: errors, fields: fields }); | ||
}, _this.onReset = function (e) { | ||
if (e) { | ||
e.preventDefault(); | ||
} | ||
_this.setState(function (prevState) { | ||
return { | ||
submitted: false, | ||
errors: Object.keys(prevState.errors).reduce(function (acc, field) { | ||
return _extends({}, acc, _defineProperty({}, field, null)); | ||
}), | ||
fields: Object.keys(prevState.fields).reduce(function (acc, field) { | ||
return _extends({}, acc, _defineProperty({}, field, '')); | ||
}) | ||
}; | ||
}); | ||
_this.props.onReset(); | ||
}, _this.onSubmit = function (e) { | ||
e.preventDefault(); | ||
if (e) { | ||
e.preventDefault(); | ||
} | ||
_this.setState({ submitted: true }); | ||
@@ -181,3 +201,5 @@ var _this$state = _this.state, | ||
register: this.registerSubComponent, | ||
resetAll: this.onReset, | ||
setField: this.setField, | ||
submit: this.onSubmit, | ||
submitted: this.state.submitted, | ||
@@ -188,3 +210,7 @@ unregister: this.unregisterSubComponent | ||
'form', | ||
_extends({ onChange: this.onChange, onSubmit: this.onSubmit }, rest), | ||
_extends({ | ||
onChange: this.onChange, | ||
onSubmit: this.onSubmit, | ||
onReset: this.onReset | ||
}, rest), | ||
_react2.default.createElement( | ||
@@ -205,2 +231,5 @@ _FormContext.FormProvider, | ||
return f; | ||
}, | ||
onReset: function onReset(f) { | ||
return f; | ||
} | ||
@@ -210,4 +239,5 @@ }; | ||
onSubmit: _propTypes.func, | ||
onReset: _propTypes.func, | ||
validators: (0, _propTypes.shape)({}).isRequired | ||
}; | ||
exports.default = (0, _ValidatorsContext.withValidators)(Form); |
@@ -82,2 +82,4 @@ 'use strict'; | ||
fields = _props2.fields, | ||
resetAll = _props2.resetAll, | ||
submit = _props2.submit, | ||
submitted = _props2.submitted, | ||
@@ -92,2 +94,4 @@ children = _props2.children, | ||
fields: this.getFields(fields), | ||
resetAll: resetAll, | ||
submit: submit, | ||
submitted: submitted, | ||
@@ -114,5 +118,7 @@ setField: setField | ||
register: _propTypes.func, | ||
resetAll: _propTypes.func, | ||
submitted: _propTypes.bool, | ||
submit: _propTypes.func, | ||
unregister: _propTypes.func | ||
}; | ||
exports.default = (0, _FormContext.withFormContext)(Validation); |
{ | ||
"name": "calidation", | ||
"version": "1.6.2", | ||
"version": "1.7.0", | ||
"description": "A red hot validation library for React", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -193,7 +193,7 @@ # calidation | ||
isRequired: 'Please fill out the password a second time', | ||
isEqual: ({ fields }) => { | ||
isEqual: ({ fields }) => ({ | ||
message: 'The two password must match', | ||
value: fields.password, | ||
validateIf: fields.password.length > 0, // this can be a boolean too! | ||
}, | ||
}), | ||
} | ||
@@ -399,3 +399,5 @@ ``` | ||
setField: func, // callback accepting a diff object, updating fields like setState | ||
submit: func, // call this to programmatically trigger a submitted state | ||
submitted: bool, // flag showing whether the form has been submitted once or not | ||
resetAll: func, // call this to programmatically trigger a full state reset | ||
} | ||
@@ -449,3 +451,4 @@ ``` | ||
This callback is fired whenever the form is submitted. That can happen whenever | ||
somebody clicks the submit button, or hits `enter` in the form. | ||
somebody clicks the submit button, hits `enter` in the form, or calls the `submit` function passed in the `children` | ||
function. | ||
@@ -462,2 +465,9 @@ The `onSubmit` function is called with an object with the following props: | ||
##### `onReset: func` | ||
This callback is fired whenever the form is reset. That can happen whenever somebody clicks a button with type "reset", | ||
or calls the `resetAll` function passed in the `children` function. | ||
The `onReset` function is called with no parameters. | ||
### `Validation` | ||
@@ -464,0 +474,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
41621
456
516