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.

changing a field value based on state of another one (for repeated, nesting field)

See original GitHub issue

In some cases I want to change the field value (in particular clear it) based on the state of another value.

I think the right way in would be form.on('update@state.city',.. and then use a clear() on the field I want to clear. But my form is a nested form, and I tried form.on('update@repeated[].value', ... with no luck: it never seems to fire.

As an alternative I tried to hook up events using form.$('repeated[].value').onChange, but the field couldn’t be found in that case.

Two questions:

  • are these strategies supposed to work, or am I going about it the wrong way?

  • is this a bug concerning nested fields and events?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
faassencommented, Feb 9, 2017

I took a look at using observable, but there is some complexity here in combination with repeated sub-forms.

I can implement an onInit that uses forEach to go through all fields, including nested ones. These fields become observable. It’s not the most expressive way to make such fields observable (I’d prefer to use the flat specification, like bars[].value), but it could be made to work.

But what happens now if someone adds a field using onAdd? This field is not observable. Instead I have to write more logic to make the values that just got added observable. I’m also not sure what would happen if I remove a field previously declared observable – maybe there’s no problem there.

I see you closed this issue, and I hope I missed something, but this isn’t a very pleasant API when dealing with repeating fields.

I think it would be useful to have a declarative callback, something like:

observers = {
  'entries[].a': (field, parentField, form) =>  { parentField.$('b').value = ""; }
}

To express the following relationship: blank the value b on the entry with the same index when entries[].a changes.

I will now investigate the other approach you suggested, where I override the event handler.

0reactions
foxhound87commented, Feb 18, 2017

Anyway both styles can be used. You can use the ‘observables’ initial object as well, this will allow to enable the observables to the new added fields.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Specify nested and repeated columns in table schemas
To create a column with nested data, set the data type of the column to RECORD in the schema. A RECORD can be...
Read more >
How to update nested state properties in React - Stack Overflow
In order to setState for a nested object you can follow the below approach as I think setState doesn't handle nested updates.
Read more >
BigQuery Nested and Repeated Fields: Dig Deeper into Data ...
Are you ready to take your knowledge of SQL to its final frontiers? Join this session to learn how you can use BigQuery...
Read more >
Working with nested and repeated fields
Repeated fields approximate a "one-to-many" relationship and provide an opportunity to define a field that can hold multiple values per row.
Read more >
BigQuery Nested Fields Simplified: A Comprehensive Guide 101
BigQuery has also added Nested and Repeated Fields for storing nested records, whether a single BigQuery Record or repeated values.
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