foxhound87 / mobx-react-form

Reactive MobX Form State Management
https://foxhound87.github.io/mobx-react-form
MIT License
1.09k stars 129 forks source link

Adding a new array item should not also adding nested array item within it #615

Closed riceyeh closed 1 year ago

riceyeh commented 1 year ago

Hi, The following 2 tests show nested array items are added when adding an array item:

it('nested array item inside array item 1', () => { const fields = [ 'options', 'options[]', 'options[].oid', 'options[].amendments', 'options[].amendments[]', 'options[].amendments[].oid', ] const $form = new Form({fields}, {name: 'form'}) const $option = $form.$('options').add() $option.update({oid: 1}) expect($form.select('options.0', null, false)).not.to.be.undefined expect($form.select('options.0.amendments.0', null, false)).to.be.undefined // <--- fail })

it('nested array item inside array item 2', () => { const fields = [ 'a', 'a[]', 'a[].oid', 'a[].b.c', 'a[].b.c[]', 'a[].b.c[].oid' ] const $form = new Form({fields}, {name: 'form'}) const $a = $form.$('a').add() $a.update({oid: 1}) expect($form.select('a.0', null, false)).not.to.be.undefined expect($form.select('a.0.b', null, false)).not.to.be.undefined expect($form.select('a.0.b.c', null, false)).not.to.be.undefined expect($form.select('a.0.b.c.0', null, false)).to.be.undefined // <--- fail })