Skip to content

Commit

Permalink
Bind all necessary methods of the HOC
Browse files Browse the repository at this point in the history
  • Loading branch information
amannn committed Nov 17, 2017
1 parent a939ed9 commit 5ea7957
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/Wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,22 @@ exports.default = function (Component) {
externalError: null,
formSubmitted: false
};

_this.getErrorMessage = _this.getErrorMessage.bind(_this);
_this.getErrorMessages = _this.getErrorMessages.bind(_this);
_this.getValue = _this.getValue.bind(_this);
_this.hasValue = _this.hasValue.bind(_this);
_this.isFormDisabled = _this.isFormDisabled.bind(_this);
_this.isPristine = _this.isPristine.bind(_this);
_this.isFormSubmitted = _this.isFormSubmitted.bind(_this);
_this.isRequired = _this.isRequired.bind(_this);
_this.isValidValue = _this.isValidValue.bind(_this);
_this.isValid = _this.isValid.bind(_this);
_this.resetValue = _this.resetValue.bind(_this);
_this.setValidations = _this.setValidations.bind(_this);
_this.setValue = _this.setValue.bind(_this);
_this.showRequired = _this.showRequired.bind(_this);
_this.showError = _this.showError.bind(_this);
return _this;
}

Expand Down
6 changes: 6 additions & 0 deletions src/Wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,22 @@ export default (Component) => {
externalError: null,
formSubmitted: false,
};

this.getErrorMessage = this.getErrorMessage.bind(this);
this.getErrorMessages = this.getErrorMessages.bind(this);
this.getValue = this.getValue.bind(this);
this.hasValue = this.hasValue.bind(this);
this.isFormDisabled = this.isFormDisabled.bind(this);
this.isPristine = this.isPristine.bind(this);
this.isFormSubmitted = this.isFormSubmitted.bind(this);
this.isRequired = this.isRequired.bind(this);
this.isValidValue = this.isValidValue.bind(this);
this.isValid = this.isValid.bind(this);
this.resetValue = this.resetValue.bind(this);
this.setValidations = this.setValidations.bind(this);
this.setValue = this.setValue.bind(this);
this.showRequired = this.showRequired.bind(this);
this.showError = this.showError.bind(this);
}

componentWillMount() {
Expand Down
37 changes: 37 additions & 0 deletions tests/Element-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,43 @@ export default {

test.done();

},

'binds all necessary methods': function (test) {
const onInputRef = input => {
[
'getErrorMessage',
'getErrorMessages',
'getValue',
'hasValue',
'isFormDisabled',
'isValid',
'isPristine',
'isFormSubmitted',
'isRequired',
'isValidValue',
'resetValue',
'setValidations',
'setValue',
'showRequired',
'showError',
].forEach(fnName => {
const fn = input[fnName];
try {
fn();
} catch(e) {
throw new Error(`Method '${fnName}' isn't bound.`);
}
});

test.done();
}

TestUtils.renderIntoDocument(
<Formsy>
<TestInput ref={onInputRef} name="name" value="foo" />
</Formsy>
);
}

};

0 comments on commit 5ea7957

Please sign in to comment.