Skip to content

Commit

Permalink
Fixed cloneElement bug on Form.js
Browse files Browse the repository at this point in the history
  • Loading branch information
s77rt committed Mar 17, 2023
1 parent 4f81115 commit c4d8509
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/components/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,24 @@ class Form extends React.Component {
.value() || '';

return React.cloneElement(child, {
ref: node => this.inputRefs[inputID] = node,
ref: (node) => {
this.inputRefs[inputID] = node;

// Call the original ref, if any
const {ref} = child;
if (_.isFunction(ref)) {
ref(node);
}
},
value: this.state.inputValues[inputID],
errorText: this.state.errors[inputID] || fieldErrorMessage,
onBlur: () => {
onBlur: (event) => {
this.setTouchedInput(inputID);
this.validate(this.state.inputValues);

if (_.isFunction(child.props.onBlur)) {
child.props.onBlur(event);
}
},
onInputChange: (value, key) => {
const inputKey = key || inputID;
Expand Down

0 comments on commit c4d8509

Please sign in to comment.