Allow floats for isNumeric

This commit is contained in:
Hana Wang 2015-02-25 10:35:30 -08:00
parent 385263c383
commit a65b2943b0
2 changed files with 34 additions and 6 deletions

View File

@ -3,7 +3,7 @@ var Formsy = require('./../src/main.js');
describe('Validation', function() {
it('should trigger an onValid handler, if passed, when form is valid', function () {
var onValid = jasmine.createSpy('valid');
var TestInput = React.createClass({
mixins: [Formsy.Mixin],
@ -27,7 +27,7 @@ describe('Validation', function() {
});
it('should trigger an onInvalid handler, if passed, when form is invalid', function () {
var onInvalid = jasmine.createSpy('invalid');
var TestInput = React.createClass({
mixins: [Formsy.Mixin],
@ -51,7 +51,7 @@ describe('Validation', function() {
});
it('RULE: isEmail', function () {
var isValid = jasmine.createSpy('valid');
var TestInput = React.createClass({
mixins: [Formsy.Mixin],
@ -79,7 +79,7 @@ describe('Validation', function() {
});
it('RULE: isNumeric', function () {
var isValid = jasmine.createSpy('valid');
var TestInput = React.createClass({
mixins: [Formsy.Mixin],
@ -107,7 +107,7 @@ describe('Validation', function() {
});
it('RULE: isNumeric (actual number)', function () {
var isValid = jasmine.createSpy('valid');
var TestInput = React.createClass({
mixins: [Formsy.Mixin],
@ -134,4 +134,32 @@ describe('Validation', function() {
});
it('RULE: isNumeric (string representation of a float)', function () {
var isValid = jasmine.createSpy('valid');
var TestInput = React.createClass({
mixins: [Formsy.Mixin],
updateValue: function (event) {
this.setValue(event.target.value);
},
render: function () {
if (this.isValid()) {
isValid();
}
return <input value={this.getValue()} onChange={this.updateValue}/>
}
});
var form = TestUtils.renderIntoDocument(
<Formsy.Form>
<TestInput name="foo" value="foo" validations="isNumeric"/>
</Formsy.Form>
);
var input = TestUtils.findRenderedDOMComponentWithTag(form, 'INPUT');
expect(isValid).not.toHaveBeenCalled();
TestUtils.Simulate.change(input, {target: {value: '1.5'}});
expect(isValid).toHaveBeenCalled();
});
});

View File

@ -14,7 +14,7 @@ var validationRules = {
if (typeof value === 'number') {
return true;
} else {
return value.match(/^-?[0-9]+$/);
return value.match(/[-+]?(\d*[.])?\d+/);
}
},
'isAlpha': function (value) {