-
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
Incorrect validation of required child properties of optional properties? #2708
Comments
I think this is related to #2669, which mentions pruning empty leaf objects before validation. |
Hi there! I would love to contribute a fix if no one has started working on this yet. I have forked the repo and gotten the playground running locally. This is my first time contributing to this repo, so any pointers are welcome. |
Hi @devinsm I'm new to this repo too, so I can't provide any guidance. I can't use the package as-is without fixing this and need to deliver an alpha of my app very soon. Have you looked into the fix at all? Otherwise, I may poke around and see what I can figure out. |
I think one problem in dealing with this will be to determine when an object really is empty and can be pruned. There is bound to be ambiguity, such as differentiating between an empty string and an undefined one, a false boolean vs. undefined, an empty array vs. undefined, etc. Also, with enum properties it will be necessary to provide an empty, '--' option so the value can be unset. (That really should be supported in general for any optional enum as well.) I'm thinking to prune recursively starting at leaf objects. If the object is optional and all of its properties are empty or false then delete it. |
It also looks like the whole way 'required' is handled needs reworking. The isRequired() method in ObjectField simply looks at the required property on the schema. The problem is that a 'required' property on an optional nested schema is not necessarily required. It would be better to simply rely on ajv validation so this code isn't basically repeating validation logic that's correctly implemented in ajv. |
Would be open to accepting a PR that changes this behavior to be consistent
with that of ajv!
Ashwin Ramaswami
…On Mon, Feb 28, 2022, 3:55 PM David Johnson ***@***.***> wrote:
It also looks like the whole way 'required' is handled needs reworking.
The isRequired() method in ObjectField simply looks at the required
property on the schema. The problem is that a 'required' property on an
optional nested schema is not necessarily required. It would be better to
simply rely on ajv validation so this code isn't basically repeating
validation logic that's correctly implemented in ajv.
—
Reply to this email directly, view it on GitHub
<#2708 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAM4MX7EFUP33YAVYNLLB4TU5POMPANCNFSM5OFOUQRA>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
The "required" attribute is misinterpreted, when an NOT required element contains required element itself. Checking out this example:
Possible but ugly workaround: |
This issue has been automatically marked as possibly close because it has not had recent activity. It will be closed if no further activity occurs. Please leave a comment if this is still an issue for you. Thank you. |
This issue was closed because of lack of recent activity. Reoopen if you still need assistance. |
Prerequisites
Description
Form validation fails if a required child property of an optional object property is missing.
Steps to Reproduce
Add the following property schema to the "Simple" example in the playground:
Submit the form without entering any address data
Expected behavior
Because address is optional and I did not enter any address, validation should succeed and the produced form should have no address property.
Actual behavior
Validation fails because the required zip property is missing.
Version
3.2.1
The text was updated successfully, but these errors were encountered: