diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 00000000..4a7ea303
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,12 @@
+root = true
+
+[*]
+indent_style = space
+indent_size = 2
+end_of_line = lf
+charset = utf-8
+trim_trailing_whitespace = true
+insert_final_newline = true
+
+[*.md]
+trim_trailing_whitespace = false
diff --git a/Gulpfile.js b/Gulpfile.js
index 4b0108d7..bb955bb4 100644
--- a/Gulpfile.js
+++ b/Gulpfile.js
@@ -8,10 +8,8 @@ var uglify = require('gulp-uglify');
var streamify = require('gulp-streamify');
var notify = require('gulp-notify');
var gutil = require('gulp-util');
-var shell = require('gulp-shell');
var livereload = require('gulp-livereload');
var glob = require('glob');
-var jasminePhantomJs = require('gulp-jasmine2-phantomjs');
var fs = require('fs');
var dependencies = ['react'];
@@ -63,7 +61,7 @@ var browserifyTask = function (options) {
// We create a separate bundle for our dependencies as they
// should not rebundle on file changes. This only happens when
- // we develop. When deploying the dependencies will be included
+ // we develop. When deploying the dependencies will be included
// in the application bundle
if (options.development) {
diff --git a/package.json b/package.json
index 3b2c9997..8907b69d 100644
--- a/package.json
+++ b/package.json
@@ -8,7 +8,7 @@
},
"main": "src/main.js",
"scripts": {
- "test": "./node_modules/.bin/jasmine-node ./specs",
+ "test": "echo \"Error: no test specified\" && exit 1",
"examples": "webpack-dev-server --config examples/webpack.config.js --content-base examples"
},
"author": "Christian Alfoni",
@@ -25,15 +25,12 @@
"glob": "^4.0.6",
"gulp": "^3.8.9",
"gulp-if": "^1.2.4",
- "gulp-jasmine2-phantomjs": "^0.1.1",
"gulp-livereload": "^3.4.0",
"gulp-notify": "^1.4.2",
- "gulp-shell": "^0.2.10",
"gulp-streamify": "0.0.5",
"gulp-uglify": "^0.3.1",
"gulp-util": "^3.0.0",
"jsx-loader": "^0.12.2",
- "phantomjs": "^1.9.12",
"reactify": "^1.1.0",
"vinyl-source-stream": "^0.1.1",
"watchify": "^2.1.1",
diff --git a/release/formsy-react.js b/release/formsy-react.js
index 419f7556..3a85e3f6 100644
--- a/release/formsy-react.js
+++ b/release/formsy-react.js
@@ -425,6 +425,7 @@ var convertValidationsToObject = function (validations) {
return validations.split(/\,(?![^{\[]*[}\]])/g).reduce(function (validations, validation) {
var args = validation.split(':');
var validateMethod = args.shift();
+
args = args.map(function (arg) {
try {
return JSON.parse(arg);
@@ -432,10 +433,11 @@ var convertValidationsToObject = function (validations) {
return arg; // It is a string if it can not parse it
}
});
-
+
if (args.length > 1) {
throw new Error('Formsy does not support multiple args on string validations. Use object format of validations instead.');
}
+
validations[validateMethod] = args.length ? args[0] : true;
return validations;
}, {});
@@ -443,8 +445,8 @@ var convertValidationsToObject = function (validations) {
}
return validations || {};
-
};
+
module.exports = {
getInitialState: function () {
return {
@@ -463,8 +465,8 @@ module.exports = {
validationErrors: {}
};
},
- componentWillMount: function () {
+ componentWillMount: function () {
var configure = function () {
this.setValidations(this.props.validations, this.props.required);
this.props._attachToForm(this);
@@ -484,7 +486,6 @@ module.exports = {
}.bind(this), 0);
}
configure();
-
},
// We have to make the validate method is kept when new props are added
@@ -495,13 +496,13 @@ module.exports = {
componentDidUpdate: function (prevProps, prevState) {
var isValueChanged = function () {
-
+
return this.props.value !== prevProps.value && this.state._value === prevProps.value;
}.bind(this);
- // If validations has changed or something outside changes
+ // If validations has changed or something outside changes
// the value, set the value again running a validation
if (isValueChanged()) {
this.setValue(this.props.value);
diff --git a/specs/Element-spec.js b/specs/Element-spec.js
index 9d1d8b09..758e73f5 100644
--- a/specs/Element-spec.js
+++ b/specs/Element-spec.js
@@ -3,7 +3,7 @@ var Formsy = require('./../src/main.js');
describe('Element', function() {
it('should return passed and setValue() value when using getValue()', function () {
-
+
var TestInput = React.createClass({
mixins: [Formsy.Mixin],
updateValue: function (event) {
@@ -27,7 +27,7 @@ describe('Element', function() {
});
it('should set back to pristine value when running reset', function () {
-
+
var reset = null;
var TestInput = React.createClass({
mixins: [Formsy.Mixin],
@@ -55,7 +55,7 @@ describe('Element', function() {
});
it('should return error message passed when calling getErrorMessage()', function () {
-
+
var getErrorMessage = null;
var TestInput = React.createClass({
mixins: [Formsy.Mixin],
@@ -80,7 +80,7 @@ describe('Element', function() {
});
it('should return true or false when calling isValid() depending on valid state', function () {
-
+
var isValid = null;
var TestInput = React.createClass({
mixins: [Formsy.Mixin],
@@ -108,7 +108,7 @@ describe('Element', function() {
});
it('should return true or false when calling isRequired() depending on passed required attribute', function () {
-
+
var isRequireds = [];
var TestInput = React.createClass({
mixins: [Formsy.Mixin],
@@ -137,7 +137,7 @@ describe('Element', function() {
});
it('should return true or false when calling showRequired() depending on input being empty and required is passed, or not', function () {
-
+
var showRequireds = [];
var TestInput = React.createClass({
mixins: [Formsy.Mixin],
@@ -166,7 +166,7 @@ describe('Element', function() {
});
it('should return true or false when calling isPristine() depending on input has been "touched" or not', function () {
-
+
var isPristine = null;
var TestInput = React.createClass({
mixins: [Formsy.Mixin],
@@ -190,7 +190,7 @@ describe('Element', function() {
var input = TestUtils.findRenderedDOMComponentWithTag(form, 'INPUT');
TestUtils.Simulate.change(input, {target: {value: 'foo'}});
expect(isPristine()).toBe(false);
-
+
});
it('should allow an undefined value to be updated to a value', function (done) {
@@ -227,7 +227,7 @@ it('should allow an undefined value to be updated to a value', function (done) {
expect(input.getDOMNode().value).toBe('foo');
done();
}, 0);
- });
+ });
it('should be able to test a values validity', function () {
@@ -255,7 +255,7 @@ it('should allow an undefined value to be updated to a value', function (done) {
expect(input.isValidValue('foo@bar.com')).toBe(true);
expect(input.isValidValue('foo@bar')).toBe(false);
- });
+ });
it('should be able to use an object as validations property', function () {
@@ -282,7 +282,7 @@ it('should allow an undefined value to be updated to a value', function (done) {
var input = TestUtils.findRenderedComponentWithType(form, TestInput);
expect(input.isValidValue('foo@bar.com')).toBe(true);
- expect(input.isValidValue('foo@bar')).toBe(false);
+ expect(input.isValidValue('foo@bar')).toBe(false);
});
it('should be able to pass complex values to a validation rule', function () {
@@ -314,7 +314,7 @@ it('should allow an undefined value to be updated to a value', function (done) {
var inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
expect(inputComponent.isValid()).toBe(true);
var input = TestUtils.findRenderedDOMComponentWithTag(form, 'INPUT');
- TestUtils.Simulate.change(input, {target: {value: 'bar'}});
+ TestUtils.Simulate.change(input, {target: {value: 'bar'}});
expect(inputComponent.isValid()).toBe(false);
});
@@ -357,7 +357,7 @@ it('should allow an undefined value to be updated to a value', function (done) {
expect(inputComponent[0].isValid()).toBe(true);
expect(inputComponent[1].isValid()).toBe(true);
var input = TestUtils.scryRenderedDOMComponentsWithTag(form, 'INPUT');
- TestUtils.Simulate.change(input[0], {target: {value: 'bar'}});
+ TestUtils.Simulate.change(input[0], {target: {value: 'bar'}});
expect(inputComponent[0].isValid()).toBe(false);
expect(inputComponent[1].isValid()).toBe(false);
});
@@ -399,12 +399,12 @@ it('should allow an undefined value to be updated to a value', function (done) {
render: function () {
return (
-
-
@@ -464,7 +464,7 @@ it('should allow an undefined value to be updated to a value', function (done) {
render: function () {
return (
-
diff --git a/specs/Rules-equals-spec.js b/specs/Rules-equals-spec.js
index b4b72db0..7e26b863 100644
--- a/specs/Rules-equals-spec.js
+++ b/specs/Rules-equals-spec.js
@@ -1,12 +1,12 @@
var Formsy = require('./../src/main.js');
describe('Rules: equals', function() {
- var TestInput, isValid, form, input;
+ var TestInput, isValid, form, input;
beforeEach(function() {
- isValid = jasmine.createSpy('valid');
-
- TestInput = React.createClass({
+ isValid = jasmine.createSpy('valid');
+
+ TestInput = React.createClass({
mixins: [Formsy.Mixin],
updateValue: function (event) {
this.setValue(event.target.value);
@@ -30,7 +30,7 @@ describe('Rules: equals', function() {
});
afterEach(function() {
- TestInput = isValid = isInvalid = form = null;
+ TestInput = isValid = isInvalid = form = null;
});
it('should fail with undefined', function () {
@@ -57,4 +57,4 @@ describe('Rules: equals', function() {
expect(isValid).toHaveBeenCalled();
});
-});
\ No newline at end of file
+});
diff --git a/specs/Rules-hasValue-spec.js b/specs/Rules-hasValue-spec.js
index 7cd71c91..2e513f25 100644
--- a/specs/Rules-hasValue-spec.js
+++ b/specs/Rules-hasValue-spec.js
@@ -1,12 +1,12 @@
var Formsy = require('./../src/main.js');
describe('Rules: hasValue', function() {
- var TestInput, isValid, form, input;
+ var TestInput, isValid, form, input;
beforeEach(function() {
- isValid = jasmine.createSpy('valid');
-
- TestInput = React.createClass({
+ isValid = jasmine.createSpy('valid');
+
+ TestInput = React.createClass({
mixins: [Formsy.Mixin],
updateValue: function (event) {
this.setValue(event.target.value);
@@ -30,7 +30,7 @@ describe('Rules: hasValue', function() {
});
afterEach(function() {
- TestInput = isValid = isInvalid = form = null;
+ TestInput = isValid = isInvalid = form = null;
});
it('should fail with undefined', function () {
@@ -51,4 +51,4 @@ describe('Rules: hasValue', function() {
expect(isValid).toHaveBeenCalled();
});
-});
\ No newline at end of file
+});
diff --git a/specs/Rules-isAlpha-spec.js b/specs/Rules-isAlpha-spec.js
index 7b711734..3eda51cb 100644
--- a/specs/Rules-isAlpha-spec.js
+++ b/specs/Rules-isAlpha-spec.js
@@ -1,12 +1,12 @@
var Formsy = require('./../src/main.js');
describe('Rules: isAlpha', function() {
- var TestInput, isValid, form, input;
+ var TestInput, isValid, form, input;
beforeEach(function() {
- isValid = jasmine.createSpy('valid');
-
- TestInput = React.createClass({
+ isValid = jasmine.createSpy('valid');
+
+ TestInput = React.createClass({
mixins: [Formsy.Mixin],
updateValue: function (event) {
this.setValue(event.target.value);
@@ -30,7 +30,7 @@ describe('Rules: isAlpha', function() {
});
afterEach(function() {
- TestInput = isValid = isInvalid = form = null;
+ TestInput = isValid = isInvalid = form = null;
});
it('should fail with undefined', function () {
@@ -57,4 +57,4 @@ describe('Rules: isAlpha', function() {
expect(isValid).toHaveBeenCalled();
});
-});
\ No newline at end of file
+});
diff --git a/specs/Rules-isEmail-spec.js b/specs/Rules-isEmail-spec.js
index 4c75cd03..0cbef829 100644
--- a/specs/Rules-isEmail-spec.js
+++ b/specs/Rules-isEmail-spec.js
@@ -4,9 +4,9 @@ describe('Rules: isEmail', function() {
var TestInput, isValid, form, input;
beforeEach(function() {
- isValid = jasmine.createSpy('valid');
-
- TestInput = React.createClass({
+ isValid = jasmine.createSpy('valid');
+
+ TestInput = React.createClass({
mixins: [Formsy.Mixin],
updateValue: function (event) {
this.setValue(event.target.value);
@@ -30,7 +30,7 @@ describe('Rules: isEmail', function() {
});
afterEach(function() {
- TestInput = isValid = isInvalid = form = null;
+ TestInput = isValid = isInvalid = form = null;
});
it('should fail with "foo"', function () {
@@ -45,4 +45,4 @@ describe('Rules: isEmail', function() {
expect(isValid).toHaveBeenCalled();
});
-});
\ No newline at end of file
+});
diff --git a/specs/Rules-isLength-spec.js b/specs/Rules-isLength-spec.js
index e4569088..f9bfeec6 100644
--- a/specs/Rules-isLength-spec.js
+++ b/specs/Rules-isLength-spec.js
@@ -1,12 +1,12 @@
var Formsy = require('./../src/main.js');
describe('Rules: isLength', function() {
- var TestInput, isValid, form, input;
+ var TestInput, isValid, form, input;
beforeEach(function() {
- isValid = jasmine.createSpy('valid');
-
- TestInput = React.createClass({
+ isValid = jasmine.createSpy('valid');
+
+ TestInput = React.createClass({
mixins: [Formsy.Mixin],
updateValue: function (event) {
this.setValue(event.target.value);
@@ -30,7 +30,7 @@ describe('Rules: isLength', function() {
});
afterEach(function() {
- TestInput = isValid = isInvalid = form = null;
+ TestInput = isValid = isInvalid = form = null;
});
it('should fail with undefined', function () {
@@ -69,4 +69,4 @@ describe('Rules: isLength', function() {
expect(isValid).toHaveBeenCalled();
});
-});
\ No newline at end of file
+});
diff --git a/specs/Rules-isNumeric-spec.js b/specs/Rules-isNumeric-spec.js
index 80487923..10bc05d9 100644
--- a/specs/Rules-isNumeric-spec.js
+++ b/specs/Rules-isNumeric-spec.js
@@ -1,12 +1,12 @@
var Formsy = require('./../src/main.js');
describe('Rules: isNumeric', function() {
- var TestInput, isValid, form, input;
+ var TestInput, isValid, form, input;
beforeEach(function() {
- isValid = jasmine.createSpy('valid');
-
- TestInput = React.createClass({
+ isValid = jasmine.createSpy('valid');
+
+ TestInput = React.createClass({
mixins: [Formsy.Mixin],
updateValue: function (event) {
this.setValue(event.target.value);
@@ -30,7 +30,7 @@ describe('Rules: isNumeric', function() {
});
afterEach(function() {
- TestInput = isValid = isInvalid = form = null;
+ TestInput = isValid = isInvalid = form = null;
});
it('should fail with undefined', function () {
@@ -69,4 +69,4 @@ describe('Rules: isNumeric', function() {
expect(isValid).toHaveBeenCalled();
});
-});
\ No newline at end of file
+});
diff --git a/specs/Rules-isWords-spec.js b/specs/Rules-isWords-spec.js
index bec480df..a2272771 100644
--- a/specs/Rules-isWords-spec.js
+++ b/specs/Rules-isWords-spec.js
@@ -1,12 +1,12 @@
var Formsy = require('./../src/main.js');
describe('Rules: isWords', function() {
- var TestInput, isValid, form, input;
+ var TestInput, isValid, form, input;
beforeEach(function() {
- isValid = jasmine.createSpy('valid');
-
- TestInput = React.createClass({
+ isValid = jasmine.createSpy('valid');
+
+ TestInput = React.createClass({
mixins: [Formsy.Mixin],
updateValue: function (event) {
this.setValue(event.target.value);
@@ -30,7 +30,7 @@ describe('Rules: isWords', function() {
});
afterEach(function() {
- TestInput = isValid = isInvalid = form = null;
+ TestInput = isValid = isInvalid = form = null;
});
it('should fail with undefined', function () {
@@ -63,4 +63,4 @@ describe('Rules: isWords', function() {
expect(isValid).toHaveBeenCalled();
});
-});
\ No newline at end of file
+});
diff --git a/specs/Rules-maxLength-spec.js b/specs/Rules-maxLength-spec.js
index 690a90dd..ea0afc70 100644
--- a/specs/Rules-maxLength-spec.js
+++ b/specs/Rules-maxLength-spec.js
@@ -1,12 +1,12 @@
var Formsy = require('./../src/main.js');
describe('Rules: maxLength', function() {
- var TestInput, isValid, form, input;
+ var TestInput, isValid, form, input;
beforeEach(function() {
- isValid = jasmine.createSpy('valid');
-
- TestInput = React.createClass({
+ isValid = jasmine.createSpy('valid');
+
+ TestInput = React.createClass({
mixins: [Formsy.Mixin],
updateValue: function (event) {
this.setValue(event.target.value);
@@ -30,7 +30,7 @@ describe('Rules: maxLength', function() {
});
afterEach(function() {
- TestInput = isValid = isInvalid = form = null;
+ TestInput = isValid = isInvalid = form = null;
});
it('should fail with undefined', function () {
@@ -69,4 +69,4 @@ describe('Rules: maxLength', function() {
expect(isValid).not.toHaveBeenCalled();
});
-});
\ No newline at end of file
+});
diff --git a/specs/Rules-minLength-spec.js b/specs/Rules-minLength-spec.js
index f442d55c..7d80fcc2 100644
--- a/specs/Rules-minLength-spec.js
+++ b/specs/Rules-minLength-spec.js
@@ -1,12 +1,12 @@
var Formsy = require('./../src/main.js');
describe('Rules: minLength', function() {
- var TestInput, isValid, form, input;
+ var TestInput, isValid, form, input;
beforeEach(function() {
- isValid = jasmine.createSpy('valid');
-
- TestInput = React.createClass({
+ isValid = jasmine.createSpy('valid');
+
+ TestInput = React.createClass({
mixins: [Formsy.Mixin],
updateValue: function (event) {
this.setValue(event.target.value);
@@ -30,7 +30,7 @@ describe('Rules: minLength', function() {
});
afterEach(function() {
- TestInput = isValid = isInvalid = form = null;
+ TestInput = isValid = isInvalid = form = null;
});
it('should fail with undefined', function () {
@@ -69,4 +69,4 @@ describe('Rules: minLength', function() {
expect(isValid).toHaveBeenCalled();
});
-});
\ No newline at end of file
+});
diff --git a/src/Mixin.js b/src/Mixin.js
index d00d41cf..811cd745 100644
--- a/src/Mixin.js
+++ b/src/Mixin.js
@@ -5,6 +5,7 @@ var convertValidationsToObject = function (validations) {
return validations.split(/\,(?![^{\[]*[}\]])/g).reduce(function (validations, validation) {
var args = validation.split(':');
var validateMethod = args.shift();
+
args = args.map(function (arg) {
try {
return JSON.parse(arg);
@@ -12,10 +13,11 @@ var convertValidationsToObject = function (validations) {
return arg; // It is a string if it can not parse it
}
});
-
+
if (args.length > 1) {
throw new Error('Formsy does not support multiple args on string validations. Use object format of validations instead.');
}
+
validations[validateMethod] = args.length ? args[0] : true;
return validations;
}, {});
@@ -23,8 +25,8 @@ var convertValidationsToObject = function (validations) {
}
return validations || {};
-
};
+
module.exports = {
getInitialState: function () {
return {
@@ -43,8 +45,8 @@ module.exports = {
validationErrors: {}
};
},
- componentWillMount: function () {
+ componentWillMount: function () {
var configure = function () {
this.setValidations(this.props.validations, this.props.required);
this.props._attachToForm(this);
@@ -64,7 +66,6 @@ module.exports = {
}.bind(this), 0);
}
configure();
-
},
// We have to make the validate method is kept when new props are added
@@ -75,13 +76,13 @@ module.exports = {
componentDidUpdate: function (prevProps, prevState) {
var isValueChanged = function () {
-
+
return this.props.value !== prevProps.value && this.state._value === prevProps.value;
}.bind(this);
- // If validations has changed or something outside changes
+ // If validations has changed or something outside changes
// the value, set the value again running a validation
if (isValueChanged()) {
this.setValue(this.props.value);