-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
setting default value for the string input refills the field when emptied up #471
Comments
This looks like a bug indeed! |
This looks to be a side effect of #442; now we propagate |
I'm adding field clearing buttons in #472. That's always been my initial plan, I'm sticking to it. |
@n1k0 Thanks for the quick response. |
The problem has simply shifted to "clear". (check out the example on the current live playground). The real fix to is only apply defaults on create of the item. At that point you can have your cake and eat it too. You can have a simple UI and have required strings that work as the user expects without "clearing" buttons, or complex ones with the clear button. While I like the clear button, I do not expect my users will understand it in the context of strings and single checkboxes. Yes they'll get the "clear" part on a string ... but understanding that that is difference from manually deleting the string is something they won't get. And then we hit the same problem as earlier again. So still very much against reverting #442. Perhaps an option on whether to treat "empty string" as "undefined" once we have the clear boxes? It can default either way, but I personally don't want the UI acting differently if the users hit the "clear" or manually deletes the string. |
OK ... I've investigated this further. It actually looks to me like it's a bug in On line 39. Simply replace: value={defaultFieldValue(formData, schema)} with value={formData} This way the default only applies on creation. This should work independently I think on whether you clear it manually or use the clear button. Currently in the live environment if you clear it displays "bazinga" on the screen but it's Note there is also what appears to be a bug with the current implementation regardless of this change (and still exists afterwards). The defaults in general appear on screen but not in the formData. I tested this on the simple tab of the playground by making the following changes (necessarily in code): firstName: {
type: "string",
title: "First name",
default: "Chuck"
}
formData: {
lastName: "Norris",
age: 75,
bio: "Roundhouse kicking asses since 1940",
password: "noneed"
} "Chuck" will appear on the form ... but not in the formData. If I were to hit "Submit" now as a user I would expect "Chuck" to be submitted but it wouldn't. As far as I can see it works as well if not better than the current situation, which to me appears there are other default issues. Unless there is some use-case I'm missing or not aware of or something I'm missing? |
Mind you if you make any OTHER change the default string will propagate to the formData ... so it would only be noticeable on a form submitted with only defaults. Uncommon but certainly possible. |
@n1k0 Thanks for that. As crumblix says, if it's a bug and fixable, that'd be the best. |
@n1k0 Just wondering if it is better to let users handling the default value themselves rather than do it inside the form engine? Such as // initialize form
const formData = Form.getDefaultFromData(jsonSchema, defaultFormData); I believed handling default value brough the "setState" in ObjectField and ArrayField which was undesirable and also caused the issue #339. |
Meanwhile I think #476 fixes this very issue and even if transitional to something better, is probably something worth considering on the short term. Feedback would be highly appreciated. |
Highlights --- - Improved performance and reactivity. - More consistent validation behavior and UX for array field items. Backward incompatible changes --- - `ObjectField` and `ArrayField` are now stateless components, their local state handling has been dropped entirely, resulting in large performance improvements. - The `defaultFieldValue` helper from the `utils` module has been removed, as it wasn't used anymore. New features --- * Fix #411: Enable required field on radio options. (#469) * Spread `formContext` to `ArrayTemplateField`, `files` and `multiselect` arrays (#456) * From #471: Non-nullable array item fields are now marked as required in the UI. Bugfixes --- * Don't pass consumed `SchemaField` class names to child component (#439) * Turn `ObjectField` and `ArrayField` into stateless components (#480) * Fix #471: Drop default value initialization at the widget level. (#476) Kudos --- Special thanks to @crumblix and @knilink for their help on this release. You guys rock!
Released in v0.43.0. |
As is shown below from the playground page.
Is this a desired behaviour? If so, is there any options to set initial value while allowing the field to be empty?
The text was updated successfully, but these errors were encountered: