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.

form.update() populates 'initial' property in array field.

See original GitHub issue

Hello. I have next fields.

fields: [
...
 {
                name: 'aliases',
                label: 'Alias domains list',
                value: [],
                bindings: 'List',
                options: {
                    validateOnChange: true
                }
            }
...
]

Custom binding is very simple and doesn’t refer to the issue.

bindings() {
        return {
            List: {
                id: 'id',
                name: 'name',
                type: 'type',
                value: 'items',
                label: 'label',
                placeholder: 'placeholder',
                disabled: 'disabled',
                onChange: 'onChange',
                onBlur: 'onBlur',
                onFocus: 'onFocus',
                autoFocus: 'autoFocus'
            }
        };
    }

In a constructor of my component I do following:

this.form = new Form();
this.form.update(this.store.activeRule);

Active rule is an object with initial values. For example aliases property contains an observable array with values [‘123’, ‘456’]. After this.form.update(this.store.activeRule); ‘aliases’ field contains initial array not only in value property, but in initial too. Because of this when I do this.form.$('aliases').sync(aliases);, I can’t update the field with new values. And it works fine when an initial array is empty. I checked how form.update() works for other fields and saw that initial property wasn’t populated. I don’t think that it is a correct behavior, but maybe I don’t understand something. I will be glad to any help.

Thanks in advance.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
AndrewGulidovcommented, Sep 8, 2017

@foxhound87 I’ve used update() instead of sync() and it works. Thank you.

1reaction
dustinphippscommented, Sep 7, 2017

@foxhound87 Thanks! Looks like set() does in fact work. Great library, by the way.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Binding an array of objects to their specific form fields for ...
I'm able to store the form data as objects in an array, but can't figure out how to load it back into the...
Read more >
Create and update a collection in a canvas app - Microsoft Learn
Watch this video to learn how to create and update a collection: ... Set the gallery's Items property, and change the fields that...
Read more >
useFieldArray - Simple React forms validation
When you append, prepend, insert and update the field array, the obj can't be empty object rather need to supply all your input's...
Read more >
Chapter 18 Forms and Form Fields - Eloquent JavaScript
The files property of a file field element is an array-like object (again, not a real array) containing the files chosen in the...
Read more >
4 Ways to Populate an Array in JavaScript - Medium
In this one-liner, the first argument of the from method is the object we want to create an array from. In this case,...
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