Search code examples
javascriptreactjsreact-admin

ArrayInput doesn't trigger onChange function when I remove item


I have added an onChange property. It works perfectly when I add a new element, but if I remove an element, the function isn't triggered.

<ArrayInput
   source="names"
   label={'Names'}
   onChange={updateNames}
   >
   <SimpleFormIterator   
      className={classes.iteratorFormItem}
      >
      <TextInput
         label=""
         source="value"
         validate={maxLength(MAX)}
         />
   </SimpleFormIterator>
</ArrayInput>

I don't understand why onChange doesn't trigger when I remove an element, because the array is modified in that case.


Solution

  • onChange isn't a supported prop of react-admin's <ArrayInput>. If it works when the user updates a sub-record, it's by accident. The documentation makes no mention of it (see https://marmelab.com/react-admin/Inputs.html#array-inputs).

    Now, it seems you want to do thing to the data when it's changed by the user. Why not use the parse option instead? (https://marmelab.com/react-admin/Inputs.html#common-input-props).