diff --git a/specs/Validation-spec.js b/specs/Validation-spec.js
index 2876286..fd2a79c 100644
--- a/specs/Validation-spec.js
+++ b/specs/Validation-spec.js
@@ -50,6 +50,37 @@ describe('Validation', function() {
});
+ it('should use provided checkValidity function', 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
+ },
+ checkValidity: function () {
+ return this.getValue() === "checkValidity";
+ }
+ });
+ var form = TestUtils.renderIntoDocument(
+
+
+
+ );
+
+ var input = TestUtils.findRenderedDOMComponentWithTag(form, 'INPUT');
+ expect(isValid).not.toHaveBeenCalled();
+ TestUtils.Simulate.change(input, {target: {value: 'checkValidity'}});
+ expect(isValid).toHaveBeenCalled();
+
+ });
+
it('RULE: isEmail', function () {
var isValid = jasmine.createSpy('valid');
diff --git a/src/main.js b/src/main.js
index 96117d7..41cadd6 100644
--- a/src/main.js
+++ b/src/main.js
@@ -232,7 +232,7 @@ Formsy.Form = React.createClass({
this.props.onChange(this.getCurrentValues());
}
- if (!component.props.required && !component._validations) {
+ if (!component.props.required && !component._validations && !component.checkValidity) {
return;
}
@@ -273,6 +273,11 @@ Formsy.Form = React.createClass({
}
}.bind(this));
}
+ if (typeof component.checkValidity === "function") {
+ // the component defines an explicit checkValidity function
+ isValid = component.checkValidity()
+ }
+
return isValid;
},