-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
initialValue is not used on child fields of SimpleFormIterator #4709
Comments
It appears the issue is caused by Suppose the initial data (api data) is {"data": [{ "child_attr_1": "ar_1", "id":1 }]} If form includes "data" as array reference, then useInitializeFormWithRecord will call form.change(key, record[key]) command on key="data"; this, in turn, will remove default values from "data".child_attr_1.
Note: after I commented out line 25 and added console.log statement, the default value was honored as seen in the second image below. |
I do not know the intent behind ignoring default values in the form; my guess on fixing the issue: we need to read current values of the field and, if null, update them with default values on update; otherwise, keep the current value; We will also need to make sure that parent elements are processed before child elements; that means we need to sort registeredFields (line 13 in the screen print above ) so that parent elements appear before children elements. |
I have updated sample applications to only include one record that displays the issue Steps to reproduce:
|
Bug confirmed, fix incoming. Thanks for the report. |
What you were expecting:
I have a property that is an array of objects. When array element exists, but a property is missing on the object, Field's initial value should work
What happened instead:
Field is empty (initial value is not assigned)
Steps to reproduce:
Related code:
Notice, however that initialValue field is honored when creating a new record
Other information:
During troubleshooting, i noticed that FieldArray children are not honoring default values when placed into FormWithRedirect; however, I confirmed that the same code worked in native react (outside of react-admin; see attached testApp.txt file, which contains App component that can be rendered in react app)
testApp.txt
)
Environment
The text was updated successfully, but these errors were encountered: