This commit is contained in:
Semigradsky 2015-04-22 19:06:53 +03:00
parent f64d2443b9
commit b18b4e8c79
15 changed files with 103 additions and 94 deletions

12
.editorconfig Normal file
View File

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

View File

@ -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'];

View File

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

View File

@ -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);
@ -436,6 +437,7 @@ var convertValidationsToObject = function (validations) {
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

View File

@ -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');
isValid = jasmine.createSpy('valid');
TestInput = React.createClass({
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 () {

View File

@ -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');
isValid = jasmine.createSpy('valid');
TestInput = React.createClass({
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 () {

View File

@ -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');
isValid = jasmine.createSpy('valid');
TestInput = React.createClass({
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 () {

View File

@ -4,9 +4,9 @@ describe('Rules: isEmail', function() {
var TestInput, isValid, form, input;
beforeEach(function() {
isValid = jasmine.createSpy('valid');
isValid = jasmine.createSpy('valid');
TestInput = React.createClass({
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 () {

View File

@ -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');
isValid = jasmine.createSpy('valid');
TestInput = React.createClass({
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 () {

View File

@ -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');
isValid = jasmine.createSpy('valid');
TestInput = React.createClass({
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 () {

View File

@ -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');
isValid = jasmine.createSpy('valid');
TestInput = React.createClass({
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 () {

View File

@ -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');
isValid = jasmine.createSpy('valid');
TestInput = React.createClass({
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 () {

View File

@ -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');
isValid = jasmine.createSpy('valid');
TestInput = React.createClass({
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 () {

View File

@ -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);
@ -16,6 +17,7 @@ var convertValidationsToObject = function (validations) {
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