diff --git a/packages/ra-ui-materialui/src/form/SimpleFormIterator.js b/packages/ra-ui-materialui/src/form/SimpleFormIterator.js index 4b3b89395fe..14f1b186c8b 100644 --- a/packages/ra-ui-materialui/src/form/SimpleFormIterator.js +++ b/packages/ra-ui-materialui/src/form/SimpleFormIterator.js @@ -85,6 +85,17 @@ export class SimpleFormIterator extends Component { fields.remove(index); }; + // Returns a boolean to indicate whether to disable the remove button for certain fields. + // If disableRemove is a function, then call the function with the current record to + // determing if the button should be disabled. Otherwise, use a boolean property that + // enables or disables the button for all of the fields. + disableRemoveField = (record, disableRemove) => { + if (typeof disableRemove === "boolean") { + return disableRemove; + } + return disableRemove && disableRemove(record); + } + addField = () => { const { fields } = this.props; this.ids.push(this.nextId++); @@ -151,7 +162,7 @@ export class SimpleFormIterator extends Component { /> ))} - {!disableRemove && ( + {!(this.disableRemoveField((records && records[index]) || {}, disableRemove)) && (