-
Notifications
You must be signed in to change notification settings - Fork 31
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
Empty values are lost #31
Comments
As for the first issue, I imagine it would often be possible to completely replace all existing values instead of trying to merge them with the output from plexus-form. It's probably harder to change this behaviour from plexus-form. As for the second issue, here's a simple test setup: https://gist.github.com/martijnvermaat/292ecd6e912a3edd89c1
Enter some text in the form and try to remove it again. The last character cannot be removed. I think this is due to this line in Please let me know if I'm wrong, but I think this is quite a typical setup for a controlled form. Whenever you provide the |
Thanks for reminding me of this issue! I thought I had partially fixed this at some point, but maybe I was just thinking about the fix. Prune is so aggressive in order to make auto-shrinking of arrays with complex entries work. A post-processing step on the result of the prune call might be a good idea. Maybe this can be relatively simple - just make sure the value has a non-null top-level object with all its properties as given in the schema present (which gets slightly non-trivial when we have a It would be incorrect to return an empty string when a numerical field is empty, as would be returning 0, so in those cases I think |
I think I briefly played around with returning I was thinking a bit more about how to work with the However, you could also prevent a render using Do you have any thoughts on what is the most obvious approach with using the |
Due to calling
plexus-objective.prune
, fields with empty input fields are not returned in the output.I think this is quite inconvenient when you are updating existing values. Once something is set, the user cannot remove it anymore. I'm not sure if it would be better to return empty strings or
null
/undefined
, but I guess for most use cases any would do.Another strange behaviour originating from this is I think a quite typical controlled form setup. Say you provide a
values
prop which is updated on submit from the form output (andsubmitOnChange
is set). Now if there is only one (string) input field, this works until you try to delete the last remaining character in it. What (I think) happens is that the DOM value becomes the empty string, which is pruned, leading tonull
for the entire form output (also by pruning), which in turn makes that thevalues
prop is ignored and theForm
component state holds on to the deleted charachter which is then also rendered again.This is also related to #7
The text was updated successfully, but these errors were encountered: