#359 - Handle metadata for all children of a list field

This commit is contained in:
Luis Correia 2017-04-13 11:02:06 +01:00
parent 7aa77baea9
commit 805f958165

View File

@ -89,17 +89,21 @@ export default class ListControl extends Component {
handleChangeFor(index) { handleChangeFor(index) {
return (newValue, newMetadata) => { return (newValue, newMetadata) => {
const { value, onChange } = this.props; const { value, metadata, onChange, forID } = this.props;
const parsedValue = (this.valueType === valueTypes.SINGLE) ? newValue.first() : newValue; const parsedValue = (this.valueType === valueTypes.SINGLE) ? newValue.first() : newValue;
onChange(value.set(index, parsedValue), newMetadata); const parsedMetadata = {
[forID]: Object.assign(metadata ? metadata.toJS() : {}, newMetadata ? newMetadata[forID] : {}),
};
onChange(value.set(index, parsedValue), parsedMetadata);
}; };
} }
handleRemove(index) { handleRemove(index) {
return (e) => { return (e) => {
e.preventDefault(); e.preventDefault();
const { value, onChange } = this.props; const { value, metadata, onChange, forID } = this.props;
onChange(value.remove(index)); const parsedMetadata = { [forID]: metadata.remove(metadata.keySeq().get(0)) };
onChange(value.remove(index), parsedMetadata);
}; };
} }
@ -193,3 +197,7 @@ export default class ListControl extends Component {
/>); />);
} }
} }
// WEBPACK FOOTER //
// ./components/Widgets/ListControl.js