diff --git a/src/main.js b/src/main.js
index bf4a3ee2..59b818ed 100644
--- a/src/main.js
+++ b/src/main.js
@@ -44,7 +44,9 @@ Formsy.Form = React.createClass({
preventExternalInvalidation: false
};
},
-
+ contextTypes: {
+ shareFormsyWithParent: React.PropTypes.func
+ },
childContextTypes: {
formsy: React.PropTypes.object
},
@@ -67,6 +69,7 @@ Formsy.Form = React.createClass({
componentWillMount: function () {
this.inputs = {};
this.model = {};
+ if(this.context.shareFormsyWithParent) this.context.shareFormsyWithParent(this);
},
componentDidMount: function () {
diff --git a/tests/Formsy-spec.js b/tests/Formsy-spec.js
index 1a52e5bd..b4ba197a 100755
--- a/tests/Formsy-spec.js
+++ b/tests/Formsy-spec.js
@@ -701,6 +701,42 @@ export default {
}
- }
-
+ },
+
+ 'should share formsy with parent through context': function (test) {
+ const TestForm = React.createClass({
+ render() {
+ return (
+
+
+
+
+ );
+ }
+ });
+
+ var formWasShared = false;
+
+ const Wrapper = React.createClass({
+ getChildContext: function() {
+ var self = this;
+ return {
+ shareFormsyWithParent: function(form){
+ formWasShared = true;
+ }
+ };
+ },
+ childContextTypes: {
+ shareFormsyWithParent: React.PropTypes.func
+ },
+ render(){
+ return
+ }
+ });
+
+ const form = TestUtils.renderIntoDocument();
+
+ test.equal(formWasShared, true);
+ test.done();
+ }
};