Fixed bugs with isValidValue and isValidForm

This commit is contained in:
christianalfoni 2015-04-07 07:24:19 +02:00
parent f1d9d6c15c
commit ad83a10894
8 changed files with 24 additions and 14 deletions

View File

@ -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"

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -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",

View File

@ -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
@ -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();
@ -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;
},
@ -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);
},

File diff suppressed because one or more lines are too long

View File

@ -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 () {

View File

@ -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);
},