1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-23 01:39:36 +01:00

Add hot fix from AD-1313 for using refs in properties

https://github.com/ascribe/onion/blob/AD-1313-Attach-thumbnail-to-piece-
in-register-form/js/components/ascribe_forms/form.js
This commit is contained in:
Brett Sun 2015-12-03 17:17:52 +01:00
parent 328d60b279
commit 9c64cf2b80

View File

@ -238,7 +238,15 @@ let Form = React.createClass({
renderChildren() { renderChildren() {
return ReactAddons.Children.map(this.props.children, (child, i) => { return ReactAddons.Children.map(this.props.children, (child, i) => {
if (child) { if (child) {
return ReactAddons.addons.cloneWithProps(child, { // Since refs will be overwritten by this functions return statement,
// we still want to be able to define refs for nested `Form` or `Property`
// children, which is why we're upfront simply invoking the callback-ref-
// function before overwriting it.
if(typeof child.ref === 'function' && this.refs[child.props.name]) {
child.ref(this.refs[child.props.name]);
}
return React.cloneElement(child, {
handleChange: this.handleChangeChild, handleChange: this.handleChangeChild,
ref: child.props.name, ref: child.props.name,
key: i, key: i,