-
-
Notifications
You must be signed in to change notification settings - Fork 245
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
Material NumField with defaultValue cannot be cleared #969
Comments
Hi @KoenLav. That's a great finding! I'm actually surprised that no one has ever reported it earlier. When it comes to fixing that, it's a little problem. Changing the I'm just thinking, what would be the best here. Maybe wrapping this code with a |
Looking at the code: if changedMap contains all fields which no longer have their original value, then changed will only be false if we haven't modified a field, so !changed will only be trur when we have changed a field, in which case we don't want to set te value indeed. |
However, I think initialValue should still be set (I don't think it matters much, but for consistency). So maybe instead of initialValue = value, set initialValue using getInitialValue and only set value if !changed? |
Well, that's not the |
When using uniforms, simpl-schema (v2) and material, all at version 3.5.1 (latest version as of writing) when we clear a NumberField (in an AutoForm with an attached schema and model) the defaultValue will be set, whereas this works fine for a TextField.
Assuming the defaultValue of a NumberField is 10, when I backspace 0 it will show 1, but once I backspace 1 it will show 10 again.
Playground example
I believe these lines combined may be the culprit (setting the value to undefined instead of empty string will cause value to be set to initialValue):
https://github.com/vazco/uniforms/blob/master/packages/uniforms-material/src/NumField.tsx#L50
https://github.com/vazco/uniforms/blob/master/packages/uniforms/src/useField.tsx#L85
The text was updated successfully, but these errors were encountered: