From d225fa3d2b93124c5c646abc161823e38f155223 Mon Sep 17 00:00:00 2001 From: Evan Seguin Date: Thu, 7 May 2015 11:34:16 -0700 Subject: [PATCH 1/8] adding an undefined check to the isSame function --- src/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils.js b/src/utils.js index e8018ea..41d6368 100644 --- a/src/utils.js +++ b/src/utils.js @@ -29,7 +29,7 @@ module.exports = { if (Array.isArray(a)) { return !this.arraysDiffer(a, b); - } else if (typeof a === 'object' && a !== null) { + } else if (typeof a === 'object' && a !== null && a !== undefined) { return !this.objectsDiffer(a, b); } From effa9de53ffc33dbeeee2a7cfc238b646b107f47 Mon Sep 17 00:00:00 2001 From: Evan Seguin Date: Thu, 7 May 2015 11:49:41 -0700 Subject: [PATCH 2/8] Adding type checks to prevent errors resulting from assuming two object properties are of the same type --- src/utils.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/utils.js b/src/utils.js index 41d6368..dd17503 100644 --- a/src/utils.js +++ b/src/utils.js @@ -27,9 +27,11 @@ module.exports = { }, isSame: function (a, b) { - if (Array.isArray(a)) { + if (typeof a !== typeof b) { + return false; + } else if (Array.isArray(a)) { return !this.arraysDiffer(a, b); - } else if (typeof a === 'object' && a !== null && a !== undefined) { + } else if (typeof a === 'object' && a !== null) { return !this.objectsDiffer(a, b); } From 5ae260820eea64056ee99c52bab7713c61d0bef7 Mon Sep 17 00:00:00 2001 From: Evan Seguin Date: Fri, 8 May 2015 09:28:58 -0700 Subject: [PATCH 3/8] adding tests and fixing a bug where an error would be thrown when comparing an object and null --- specs/Utils-spec.jsx | 12 ++++++++++++ src/utils.js | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/specs/Utils-spec.jsx b/specs/Utils-spec.jsx index 8829524..c8dbe7c 100644 --- a/specs/Utils-spec.jsx +++ b/specs/Utils-spec.jsx @@ -11,9 +11,21 @@ describe('Utils', function() { var objD = [{ foo: ['bar'] }]; + var objE, objF; + var objG = null; + var objH = null; + expect(utils.isSame(objA, objB)).toBe(true); expect(utils.isSame(objC, objD)).toBe(true); expect(utils.isSame(objA, objD)).toBe(false); + + expect(utils.isSame(objE, objF)).toBe(true); + expect(utils.isSame(objA, objF)).toBe(false); + expect(utils.isSame(objE, objA)).toBe(false); + + expect(utils.isSame(objG, objH)).toBe(true); + expect(utils.isSame(objA, objH)).toBe(false); + expect(utils.isSame(objG, objA)).toBe(false); }); diff --git a/src/utils.js b/src/utils.js index dd17503..c034989 100644 --- a/src/utils.js +++ b/src/utils.js @@ -31,7 +31,7 @@ module.exports = { return false; } else if (Array.isArray(a)) { return !this.arraysDiffer(a, b); - } else if (typeof a === 'object' && a !== null) { + } else if (typeof a === 'object' && a !== null && b !== null) { return !this.objectsDiffer(a, b); } From 49d7d3900583dd30e54fbf41ecec6ff6d3afb08f Mon Sep 17 00:00:00 2001 From: Semigradsky Date: Mon, 11 May 2015 13:48:22 +0300 Subject: [PATCH 4/8] :lipstick: cleanup --- examples/custom-validation/app.js | 4 ++-- examples/login/app.js | 12 ++++++------ examples/webpack.config.js | 7 ++++--- src/utils.js | 5 +++-- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/examples/custom-validation/app.js b/examples/custom-validation/app.js index 6262315..72ad9fe 100644 --- a/examples/custom-validation/app.js +++ b/examples/custom-validation/app.js @@ -1,5 +1,5 @@ var React = require('react'); -var Formsy = require('./../..'); +var Formsy = require('formsy-react'); var currentYear = new Date().getFullYear(); @@ -120,4 +120,4 @@ var Validations = React.createClass({ } }); -React.render(, document.getElementById('example')); \ No newline at end of file +React.render(, document.getElementById('example')); diff --git a/examples/login/app.js b/examples/login/app.js index 8b1a4f7..24439c2 100644 --- a/examples/login/app.js +++ b/examples/login/app.js @@ -1,5 +1,5 @@ var React = require('react'); -var Formsy = require('./../..'); +var Formsy = require('formsy-react'); var App = React.createClass({ getInitialState: function() { @@ -34,7 +34,7 @@ var MyOwnInput = React.createClass({ // Add the Formsy Mixin mixins: [Formsy.Mixin], - // setValue() will set the value of the component, which in + // setValue() will set the value of the component, which in // turn will validate it and the rest of the form changeValue: function (event) { this.setValue(event.currentTarget.value); @@ -42,9 +42,9 @@ var MyOwnInput = React.createClass({ render: function () { // Set a specific className based on the validation - // state of this component. showRequired() is true - // when the value is empty and the required prop is - // passed to the input. showError() is true when the + // state of this component. showRequired() is true + // when the value is empty and the required prop is + // passed to the input. showError() is true when the // value typed is invalid var className = this.props.className + ' ' + (this.showRequired() ? 'required' : this.showError() ? 'error' : null); @@ -62,4 +62,4 @@ var MyOwnInput = React.createClass({ } }); -React.render(, document.getElementById('example')); \ No newline at end of file +React.render(, document.getElementById('example')); diff --git a/examples/webpack.config.js b/examples/webpack.config.js index eb06ae3..d306e49 100644 --- a/examples/webpack.config.js +++ b/examples/webpack.config.js @@ -13,8 +13,9 @@ module.exports = { entry: fs.readdirSync(__dirname).reduce(function (entries, dir) { var isDraft = dir.charAt(0) === '_'; - if (!isDraft && isDirectory(path.join(__dirname, dir))) + if (!isDraft && isDirectory(path.join(__dirname, dir))) { entries[dir] = path.join(__dirname, dir, 'app.js'); + } return entries; }, {}), @@ -34,7 +35,7 @@ module.exports = { resolve: { alias: { - 'react-router': '../../modules/index' + 'formsy-react': '../../src/main' } }, @@ -45,4 +46,4 @@ module.exports = { }) ] -}; \ No newline at end of file +}; diff --git a/src/utils.js b/src/utils.js index c034989..074885d 100644 --- a/src/utils.js +++ b/src/utils.js @@ -12,6 +12,7 @@ module.exports = { } return isDifferent; }, + objectsDiffer: function (a, b) { var isDifferent = false; if (Object.keys(a).length !== Object.keys(b).length) { @@ -23,10 +24,10 @@ module.exports = { } }, this); } - return isDifferent; + return isDifferent; }, - isSame: function (a, b) { + isSame: function (a, b) { if (typeof a !== typeof b) { return false; } else if (Array.isArray(a)) { From c9078b69c2260ff6a3346bf35d6689f0a45f460a Mon Sep 17 00:00:00 2001 From: Semigradsky Date: Mon, 11 May 2015 13:49:01 +0300 Subject: [PATCH 5/8] Added testing in io.js --- .travis.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 50a1d86..e616d52 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ language: node_js node_js: - - "0.12" - - "0.11" - - "0.10" + - 'iojs' + - '0.12' + - '0.11' + - '0.10' From 538003698ca05a2e20569d85c3f88d7629b50b98 Mon Sep 17 00:00:00 2001 From: Dmitry Semigradsky Date: Tue, 12 May 2015 12:50:04 +0300 Subject: [PATCH 6/8] Update README.md --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 560a5ec..cfb203b 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,11 @@ This code results in a form with a submit button that will run the `submit` meth ``` The form element component is what gives the form validation functionality to whatever you want to put inside this wrapper. You do not have to use traditional inputs, it can be anything you want and the value of the form element can also be anything you want. As you can see it is very flexible, you just have a small API to help you identify the state of the component and set its value. +## Related projects +- [formsy-react-components](https://github.com/twisty/formsy-react-components) - A set of React JS components for use in a formsy-react form +- ... +- Send PR for adding your project to this list! + ## Contribute - Fork repo - `npm install` From 5b2ca883f3ced4d2bdc80f2708d632648af8417c Mon Sep 17 00:00:00 2001 From: Alex Vaos Date: Fri, 15 May 2015 10:59:16 -0700 Subject: [PATCH 7/8] typeo in error message --- src/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.js b/src/main.js index 4f978e2..3c46d1c 100644 --- a/src/main.js +++ b/src/main.js @@ -131,7 +131,7 @@ Formsy.Form = React.createClass({ var component = this.inputs[name]; if (!component) { - throw new Error('You are trying to update an input that does not exists. Verify errors object with input names. ' + JSON.stringify(errors)); + throw new Error('You are trying to update an input that does not exist. Verify errors object with input names. ' + JSON.stringify(errors)); } var args = [{ From cca4973382a6c85be4f4e1f844c656d67bc8ffa8 Mon Sep 17 00:00:00 2001 From: semigradsky Date: Fri, 15 May 2015 21:53:08 +0300 Subject: [PATCH 8/8] Changed loader for examples. --- examples/webpack.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/webpack.config.js b/examples/webpack.config.js index d306e49..ca9992b 100644 --- a/examples/webpack.config.js +++ b/examples/webpack.config.js @@ -29,7 +29,7 @@ module.exports = { module: { loaders: [ - { test: /\.js$/, exclude: /node_modules/, loader: 'jsx-loader' } + { test: /\.js$/, exclude: /node_modules/, loader: 'babel' } ] },