Skip to content

Commit

Permalink
Fixed bugs with isValidValue and isValidForm
Browse files Browse the repository at this point in the history
  • Loading branch information
christianalfoni committed Apr 7, 2015
1 parent f1d9d6c commit ad83a10
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 14 deletions.
2 changes: 1 addition & 1 deletion bower.json
@@ -1,6 +1,6 @@
{
"name": "formsy-react",
"version": "0.10.0",
"version": "0.10.1",
"main": "src/main.js",
"dependencies": {
"react": "^0.11.2 || ^0.13.1"
Expand Down
4 changes: 3 additions & 1 deletion build/formsy-react.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions build/specs.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "formsy-react",
"version": "0.10.0",
"version": "0.10.1",
"description": "A form input builder and validator for React JS",
"repository": {
"type": "git",
Expand Down
20 changes: 13 additions & 7 deletions release/formsy-react.js
Expand Up @@ -228,20 +228,21 @@ Formsy.Form = React.createClass({displayName: "Form",
// validate the input and set its state. Then check the
// state of the form itself
validate: function (component) {

// Trigger onChange
if (this.state.canChange) {
this.props.onChange(this.getCurrentValues());
}

if (!component.props.required && !component._validations) {
return;
var isValid = true;
if (component.validate && typeof component.validate === 'function') {
isValid = component.validate();
} else if (component.props.required || component._validations) {
isValid = this.runValidation(component);
}

// Run through the validations, split them up and call
// the validator IF there is a value or it is required
var isValid = this.runValidation(component);

component.setState({
_isValid: isValid,
_serverError: null
Expand All @@ -253,9 +254,8 @@ Formsy.Form = React.createClass({displayName: "Form",
runValidation: function (component, value) {

var isValid = true;

value = arguments.length === 2 ? value : component.state._value;
if (component._validations.length && (component.props.required || value !== '')) {
if (component._validations.length) {
component._validations.split(/\,(?![^{\[]*[}\]])/g).forEach(function (validation) {
var args = validation.split(':');
var validateMethod = args.shift();
Expand All @@ -275,6 +275,10 @@ Formsy.Form = React.createClass({displayName: "Form",
}
}.bind(this));
}
if (typeof component.validate === "function") {
// the component defines an explicit validate function
isValid = component.validate()
}
return isValid;
},

Expand Down Expand Up @@ -406,6 +410,8 @@ module.exports = {
nextProps._attachToForm = this.props._attachToForm;
nextProps._detachFromForm = this.props._detachFromForm;
nextProps._validate = this.props._validate;
nextProps._isValidValue = this.props._isValidValue;
nextProps._isFormDisabled = this.props._isFormDisabled;
this.setValidations(nextProps.validations, nextProps.required);
},

Expand Down
2 changes: 1 addition & 1 deletion release/formsy-react.min.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion specs/Element-spec.js
Expand Up @@ -326,7 +326,6 @@ it('should allow an undefined value to be updated to a value', function (done) {
});
},
setInvalid: function () {
console.log('Running it!');
isInvalid = true;
},
render: function () {
Expand Down
2 changes: 2 additions & 0 deletions src/Mixin.js
Expand Up @@ -37,6 +37,8 @@ module.exports = {
nextProps._attachToForm = this.props._attachToForm;
nextProps._detachFromForm = this.props._detachFromForm;
nextProps._validate = this.props._validate;
nextProps._isValidValue = this.props._isValidValue;
nextProps._isFormDisabled = this.props._isFormDisabled;
this.setValidations(nextProps.validations, nextProps.required);
},

Expand Down

0 comments on commit ad83a10

Please sign in to comment.