mobx-react-form
mobx-react-form copied to clipboard
It's impossible to clear or reset arrays
clear
- leaves empty elements in arrays.
reset
- leaves added elements in arrays and isDirty
flag.
defaults
, initials
- return modified arrays.
it's visible even on demo page https://foxhound87.github.io/mobx-react-form-demo/demo.html
The clear and reset are behaving correctly. default and initials are correct. please give more explanation.
after clear: https://www.dropbox.com/s/r2lri29c6gkgk8g/after%20clear.png?dl=0 clear should remove all fields that could be added manually.
before reset: https://www.dropbox.com/s/oy12gr1c1hwqnqo/before%20reset.png?dl=0 default & initial are set. form was modified by clear and by delete on top array elements.
after reset: https://www.dropbox.com/s/8srhnwmwn7o1eqj/after%20reset.png?dl=0 default & initial are ignored for array. same for adding, there is no option to revert changes on array.
defaults & initials after adding: https://www.dropbox.com/s/zs0z0sc8lvd2fmx/defaults%26initials.png?dl=0
Thank you for the explanation, The behavior has been always like this, I have to figure out if it can be enhanced.
@JulianWielga @foxhound87 do you have solution for this? I need to reset nested fields array but it does not do that. Actually the exact behavior you described.
I forgot to mention that update()
can be used to reset/clear arrays:
for example we have members[]
in fields struct we can remove the elements with:
instance.update({ members: [] })
which (almost) is the same of:
instance.$('members').each((field) => field.del())
reset and clear example (using values):
const members = instance.$('members').values();
instance.update({ members: [] }) // clear
instance.update({ members }) // reset