Merge pull request #28 from hahahana/isNumeric
Allow floats in isNumeric
This commit is contained in:
commit
cf93061296
|
|
@ -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();
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue