Skip to content
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

Why form is not 'dirty' after adding/removing object in array? #749

Closed
olegkalyta opened this issue Mar 17, 2016 · 7 comments
Closed

Why form is not 'dirty' after adding/removing object in array? #749

olegkalyta opened this issue Mar 17, 2016 · 7 comments

Comments

@olegkalyta
Copy link

I need to save added objects in array & be able to save state, if objects were deleted from array.
In other words, i try to accomplish this behavior:

  1. I have initialised array with 1 object inside
  2. After adding, removing any objects in this array, i expect to have dirty form, but it is not.

Please check gist with this example:
https://gist.github.com/olegkalyta/f6623b5c645c22581650

@clayne11
Copy link
Contributor

Shallow equality cannot detect when you change an element inside an array. You need to return a new array without the element you want to remove rather than mutating the existing array.

@olegkalyta
Copy link
Author

You mean, explicitly mutate state in my own handle array methods and do not use

formReducer.plugin 'redux-form/ADD_ARRAY_VALUE' ?

@olegkalyta
Copy link
Author

In my gist, i use standard methods for adding/removing array elements and i thought, they should return new arrays to change form status to dirty.
Anyway, as @clayne11 adviced, i manually return new arrays in plugin, but it still does not work for me.
https://gist.github.com/olegkalyta/d3a1f8e120576add7e55

@erikras is there some sort of best practise for such task?

@erikras
Copy link
Member

erikras commented Mar 21, 2016

This is unfortunately a known bug (#391, #484) that is being taken into consideration for the next version, but for now, I'm afraid you're going to have to do array length checks yourself.

@skormos
Copy link

skormos commented Mar 27, 2016

+1 for this being implemented. WRT to form dirtiness, if I touch a field, the form is dirty, so why not apply the same at the form level? If I touch the form by adding or removing fields, the form itself should be dirty.

@ooflorent
Copy link
Contributor

Please continue the discussion in #391.

@lock
Copy link

lock bot commented Jun 3, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants