Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
riceyeh opened this issue Oct 3, 2022 · 0 comments
Closed

Comments

@riceyeh
Copy link
Contributor

riceyeh commented Oct 3, 2022

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
})

riceyeh added a commit to riceyeh/mobx-react-form that referenced this issue Oct 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants