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.

Problem watching complex custom fields

See original GitHub issue

I’m trying to implement a single source of truth via react-hook-form for my dynamic form. Let’s say there is a dynamic array of objects (animals) with props name and type, so the fields will have the following names: animals[index].name and animals[index].type. And type is a custom field. I watch all the animals using watch('animals'), animals can be added and removed dynamically and I have a few animals defined initially.

The problem appears when I try to register a custom field that has nested props, i.e. register({name: 'animals[0].type'}). It doesn’t matter if I have defaultValues suppled to the watch method or not I have the following error:

Uncaught TypeError: Cannot convert undefined or null to object

One possible workaround that I figured out is to manually set initial value right after the field was registered, i.e. setValue('animals[0].type', 'Cat'). But this makes the form dirty and it’s not the behavior I want for the initial fields.

The second issue is that even if I put type: 'custom' it won’t re-render component after setValue is called. I believe this is only when it’s a complex field (with nested props) and when you watch not all fields.

Expected behavior

  1. watch method should either use defaultValues provided as the second argument when trying to resolve values for complex custom fields or just use undefined if defaultValues wasn’t provided
  2. setValue should trigger re-render if a field was registered with type: 'custom' prop even if it’s a complex custom field.

P.S. Thank you for your great work on this library!

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
GProstcommented, Nov 23, 2019

@bluebill1049 yep, will do! But probably tomorrow morning already 👍

0reactions
bluebill1049commented, Nov 23, 2019

no worries 😃 whenever you have some free time 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

The ultimate guide to managing Jira custom fields effectively
Custom fields complement the built-in fields in Jira by allowing you to track information specific to your team's needs inside Jira issues.
Read more >
Bulk editing issue with ACF custom fields - WordPress.org
This is kind of an issue because it is difficult to edit the custom fields if they are normal text field. I'll try...
Read more >
Troubleshooting issues while adding custom fields
Troubleshooting issues while adding custom fields ; 1. Verify if the custom field is added correctly in BMC Remedy Developer Studio. To verify...
Read more >
Next-Gen Project Issue With Custom Fields Across M...
Next-Gen projects don't use custom fields globally across projects like classic projects, that is why you don't see a "field scheme." So, currently...
Read more >
Build a Suggestion Box App Adding Custom Fields Challenge ...
here's what's wrong: The Suggestion custom object does not contain the correct set of custom fields. Tip: check for typos in the field...
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