Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/on all fields filled #42

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "react-bootstrap-validation",
"version": "0.1.11",
"version": "0.1.12",
"description": "Form validation for react-bootstrap",
"main": "./lib/index.js",
"repository": {
"type": "git",
"url": "https://github.com/heilhead/react-bootstrap-validation.git"
"url": "https://github.com/MakerStudios/react-bootstrap-validation.git"
},
"bugs": {
"url": "https://github.com/heilhead/react-bootstrap-validation/issues"
"url": "https://github.com/MakerStudios/react-bootstrap-validation/issues"
},
"directories": {
"lib": "lib/"
Expand All @@ -25,7 +25,7 @@
],
"author": "Ivan Reshetnikov <[email protected]>",
"license": "MIT",
"homepage": "https://github.com/heilhead/react-bootstrap-validation",
"homepage": "https://github.com/MakerStudios/react-bootstrap-validation",
"peerDependencies": {
"react": ">=0.13"
},
Expand Down
24 changes: 17 additions & 7 deletions src/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,14 @@ export default class Form extends InputContainer {
}

_validateInput(name) {
this._validateOne(name, this.getValues());
let result = this._validateOne(name, this.getValues());

if (typeof this.props.validateAllCallback === 'function') {
let values = this.getValues();
let { isValid, errors } = this._validateAll(values, false);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

errors is unused here


this.props.validateAllCallback(isValid);
}
}

_hasError(iptName) {
Expand All @@ -175,7 +182,7 @@ export default class Form extends InputContainer {
});
}

_validateOne(iptName, context) {
_validateOne(iptName, context, setError=true) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sure the argument in the function has proper spacing,
setError = true vs setError =true

let input = this._inputs[iptName];

if (Array.isArray(input)) {
Expand All @@ -189,8 +196,8 @@ export default class Form extends InputContainer {
let validate = input.props.validate;
let result, error;

if (typeof validate === 'function') {
result = validate(value, context);
if (typeof validate === 'function') {
result = validate(value, context);
} else if (typeof validate === 'string') {
result = this._validators[iptName](value);
} else {
Expand All @@ -210,12 +217,14 @@ export default class Form extends InputContainer {
}
}

this._setError(iptName, !isValid, error);
if (setError) {
this._setError(iptName, !isValid, error);
}

return isValid;
}

_validateAll(context) {
_validateAll(context, setError=true) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same thing about spaces between assignment

let isValid = true;
let errors = [];

Expand All @@ -233,7 +242,7 @@ export default class Form extends InputContainer {
}
} else {
Object.keys(this._inputs).forEach(iptName => {
if (!this._validateOne(iptName, context)) {
if (!this._validateOne(iptName, context, setError)) {
isValid = false;
errors.push(iptName);
}
Expand Down Expand Up @@ -331,6 +340,7 @@ Form.propTypes = {
onInvalidSubmit: React.PropTypes.func,
validateOne : React.PropTypes.func,
validateAll : React.PropTypes.func,
validateAllCallback: React.PropTypes.func,
validationEvent: React.PropTypes.oneOf([
'onChange', 'onBlur', 'onFocus'
]),
Expand Down