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.

Don't treat redundant 'initialValue' at Form.Item level as warning

See original GitHub issue
  • I have searched the issues of this repository and believe that this is not a duplicate.

What problem does this feature solve?

Currently, if a field is set w/ initialValues prop on the Form component, and again set at the Form.Item level w/ the initialValue prop, Antd logs a verbose warning in the console: Warning: Form already set 'initialValues' with path 'my_list.0.my_field'. Field can not overwrite it.

This can be especially obtrusive if you have the same component rendered multiple times, thus causing a big wall of red text.

In my view, I think that setting initialValue at both levels should be viewed as okay usage, and the behavior should stay as is but w/o a warning (i.e. the value at the top level is used instead of the value at the Form.Item) This is the case if you initialize the form state w/ existing data when the Form component is first rendered, but would like a default value at the component level if the field is not initially set. In some places we use form.getFieldValue to check whether the field has been initialized, but in other places this would be quite tedious, and generally I think it is not necessary to have to write out this logic.

Please let me know your thoughts, thank you!

What does the proposed API look like?

No API change. Just stop logging a warning.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:10
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
NightFox7commented, Oct 8, 2021

I think I have the same issue here. I want to initialize my form with the saved values when editing so I put the saved object in the initialValues of the <Form> component. However, each <Form.Item> can have a default/initial value. And in this case, I get lots of annoying error/warning logs. Am I doing something wrong here or this use case is not managed ?

3reactions
lb-aivisioncommented, Jul 23, 2020

I also approve @dobrynin use-case.

Furthermore, Antd documentation (https://ant.design/components/form/#Form.Item) states that:

initialValue | Config sub default value. Form initialValues get higher priority when conflict

When reading this documentation I assume that current behavior (upper level priority) is expected and totally normal. Why the warning if the docs tells you exactly what you can expect? It’s not like it’s a surprise…

If you really want to go for this design, please at least update the documentation. Maybe there is some side-effects we should know about?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to set initialValue for dynamic form field (ant design)?
I found an easier implementation. Turns out add method allows one to set field defaultValue . <Form.Item> <Button type="dashed" onClick={() ...
Read more >
antd-react-form-builder-ctf - npm package
Learn more about antd-react-form-builder-ctf: package health score, popularity, security, maintenance, ... You can also set initialValue for each field.
Read more >
Form
High performance Form component with data scope management. ... Basic Form data control. Includes layout, initial values, validation and submit. expand code.
Read more >
form item checkbox antd - You.com | The search engine ...
You can control the checked value of the checkbox and use that state to conditionally render another form item. There is an example...
Read more >
Personal experience with Ant forms
Item component, which is good enough for simple use cases, but has some limitations. First of all you can only work with 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