Skip to content

Commit 5ea7957

Browse files
committed
Bind all necessary methods of the HOC
1 parent a939ed9 commit 5ea7957

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

lib/Wrapper.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,22 @@ exports.default = function (Component) {
8686
externalError: null,
8787
formSubmitted: false
8888
};
89+
8990
_this.getErrorMessage = _this.getErrorMessage.bind(_this);
9091
_this.getErrorMessages = _this.getErrorMessages.bind(_this);
9192
_this.getValue = _this.getValue.bind(_this);
93+
_this.hasValue = _this.hasValue.bind(_this);
9294
_this.isFormDisabled = _this.isFormDisabled.bind(_this);
9395
_this.isPristine = _this.isPristine.bind(_this);
96+
_this.isFormSubmitted = _this.isFormSubmitted.bind(_this);
9497
_this.isRequired = _this.isRequired.bind(_this);
98+
_this.isValidValue = _this.isValidValue.bind(_this);
9599
_this.isValid = _this.isValid.bind(_this);
96100
_this.resetValue = _this.resetValue.bind(_this);
101+
_this.setValidations = _this.setValidations.bind(_this);
97102
_this.setValue = _this.setValue.bind(_this);
98103
_this.showRequired = _this.showRequired.bind(_this);
104+
_this.showError = _this.showError.bind(_this);
99105
return _this;
100106
}
101107

src/Wrapper.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,22 @@ export default (Component) => {
5959
externalError: null,
6060
formSubmitted: false,
6161
};
62+
6263
this.getErrorMessage = this.getErrorMessage.bind(this);
6364
this.getErrorMessages = this.getErrorMessages.bind(this);
6465
this.getValue = this.getValue.bind(this);
66+
this.hasValue = this.hasValue.bind(this);
6567
this.isFormDisabled = this.isFormDisabled.bind(this);
6668
this.isPristine = this.isPristine.bind(this);
69+
this.isFormSubmitted = this.isFormSubmitted.bind(this);
6770
this.isRequired = this.isRequired.bind(this);
71+
this.isValidValue = this.isValidValue.bind(this);
6872
this.isValid = this.isValid.bind(this);
6973
this.resetValue = this.resetValue.bind(this);
74+
this.setValidations = this.setValidations.bind(this);
7075
this.setValue = this.setValue.bind(this);
7176
this.showRequired = this.showRequired.bind(this);
77+
this.showError = this.showError.bind(this);
7278
}
7379

7480
componentWillMount() {

tests/Element-spec.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,43 @@ export default {
608608

609609
test.done();
610610

611+
},
612+
613+
'binds all necessary methods': function (test) {
614+
const onInputRef = input => {
615+
[
616+
'getErrorMessage',
617+
'getErrorMessages',
618+
'getValue',
619+
'hasValue',
620+
'isFormDisabled',
621+
'isValid',
622+
'isPristine',
623+
'isFormSubmitted',
624+
'isRequired',
625+
'isValidValue',
626+
'resetValue',
627+
'setValidations',
628+
'setValue',
629+
'showRequired',
630+
'showError',
631+
].forEach(fnName => {
632+
const fn = input[fnName];
633+
try {
634+
fn();
635+
} catch(e) {
636+
throw new Error(`Method '${fnName}' isn't bound.`);
637+
}
638+
});
639+
640+
test.done();
641+
}
642+
643+
TestUtils.renderIntoDocument(
644+
<Formsy>
645+
<TestInput ref={onInputRef} name="name" value="foo" />
646+
</Formsy>
647+
);
611648
}
612649

613650
};

0 commit comments

Comments
 (0)