question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

.set() array as value without nested fields not working

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:15 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
d4rky-plcommented, Apr 5, 2017

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 😃

0reactions
foxhound87commented, Apr 5, 2017

Anyway thank you for expressing your experience with the package. It is good to understand a different point of view in order to make a better documentation. Let me know if you have more questions. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Javascript: how to dynamically create nested objects using ...
I have an Object called "Settings" and I would like to write a function that adds new settings to that object. The new...
Read more >
How can update an item in a nested array, or add ... - MongoDB
My attempted solution: Does not work. Can't use $set and $setOnInsert with the same field. exports.wordListAddorEditNOTWORKING = async (req, res) ...
Read more >
Nested field type | Elasticsearch Guide [8.5] | Elastic
The nested type is a specialised version of the object data type that allows arrays of objects to be indexed in a way...
Read more >
Nested Objects and Arrays - VeeValidate
vee-validate supports nested objects and arrays by using field name syntax to indicate a field's path. This allows you to structure forms easily...
Read more >
Work with arrays | BigQuery - Google Cloud
You can combine arrays using functions like ARRAY_CONCAT() , and convert arrays to strings ... You can also flatten ARRAY type fields of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found