mobx-react-form: .set() array as value without nested fields not working

Case (unified properties, don’t mind the field name, I’m still struggling with making things work):

  role_id: {
    label: 'Role',
    rules: 'array',
    default: [],
    value: []
  },

Example of bad behaviour(s):

$r.form.$('role_id').set('value', [123])
$r.form.$('role_id').value # [123]

$r.form.$('role_id').set('value', [456])
$r.form.$('role_id').value # [456]

$r.form.$('role_id').set('value', [])
$r.form.$('role_id').value # [456] <- this should be [] instead

$r.form.$('role_id').update([]) # this also doesn't work
$r.form.set('value', { role_id: [] }) # still nope

$r.form.update({ role_id: [] }) 
$r.form.$('role_id').value # => "a"   <- wait, what

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 15 (8 by maintainers)

Most upvoted comments

All right, I dug deeper and I think the problem actually lies between the chair and the computer. This works:

$.form.update({ role_id: [1,2,3] })
$.form.update({ role_id: [] })

I realize that this is by design but it might be a good idea to write down an explanation of differences between set(value) / set('value', value), update() and sync(). I’m afraid the documentation doesn’t really differentiate between those three. I will be writing a blogpost this/next week about my experiences and tips for mobx-react-form so if you’d be so kind to just give a short explanation here, I’ll be very happy to include it and you could link the comment in FAQ 😃