[updated] trim empty objects to allow correct validation of optional objects with mandatory fields#2879
Conversation
|
I just realized that I accidentally brought back a test file. Currently fixing that. |
1 similar comment
|
I just realized that I accidentally brought back a test file. Currently fixing that. |
…th mandatory values
When a nested value is also undefined, it would go up the trimming chain
and return undefined instead of {}.
For instance, `allOf if then else` would fail because the `enum` would be trimmed.
bdfc98a to
20a66e8
Compare
|
Actually the more I look at this the less I understand.. The original PR only trims extra data on validation, but doesn't do anything for the submitted data. With this schema: {
"type": "object",
"properties": {
"test": {
"type": "object",
"properties": {"nested": {"type": "string", "required": "true"}}
}
}
}If no field is filled then the form will validate successfully but the submitted data will be My second issue is that I don't know what the intended behavior is when dealing with the tests for {
"type": "object",
"properties": {
"street_address": {
"type": "string"
},
"country": {
"enum": [
"United States of America",
"Canada",
"United Kingdom",
"France"
]
}
},
"allOf": [
{
"if": {
"properties": {
"country": {
"const": "United States of America"
}
}
},
"then": {
"properties": {
"zipcode": {
"type": "string"
}
}
}
},
{
"if": {
"properties": {
"country": {
"const": "United Kingdom"
}
}
},
"then": {
"properties": {
"postcode": {
"type": "string"
}
}
}
},
{
"if": {
"properties": {
"country": {
"const": "France"
}
}
},
"then": {
"properties": {
"telephone": {
"type": "string"
}
}
}
}
]
}This leads me to believe that maybe the right approach is to detect empty filed in the UI and set the to |
|
@azertyfun As part of the pending v5 release we are moving utils and validation into separate packages. It also sounds like you aren't confident that this fix is doing what is intended? |
|
Well I'm not sure what it is that is intended. The semantics of getting rid of fields in complex cases is really unclear/undefined, and would require a lot more thought than I could give it in the relatively short timespan I could spend on this PR. I was hoping to revive the old discussion on trimming non-required forms so we can iron out the edge cases, but if you are refactoring all this then I guess we should try again after that's done. |
|
@azertyfun I am done with all the refactoring. The code you originally changed is now located in |
|
Hi @heath-freenome, have issue described by @azertyfun been resolved? If not I would like to offer my help with resolving that. I'm facing same problem. |
|
Sorry for the lack of feedback. The internal tool we have that relies on rjsf has been put in an indefinite "works well enough for me" state and I haven't had time (nor will I anytime soon) to progress on this further. @PrzemyslawMikos feel free to carry on. I'm not sure if there's anything on the work I did that's particularly useful; the approach I based my work on was quite naive, mostly because it conflates The idea was to iterate over everything to remove all parts of the hierarchy that only lead to I still stand by the idea that a much better solution is that the RJSF frontend should be the one that sets fields to However this is a much bigger change than I had anticipated; the frontend needs to support this, across all rendering engines (react, antd, etc.). IDK how that plays out with existing user-defined field templates; that may end up being a breaking change. Also there will probably be many edge cases to figure out and tests to add and fix. Regardless I'm closing this PR as I'm not likely to work on it any time soon, but feel free to create your own and tag me if you have questions! Though of course I'm neither an owner nor an expert on RJSF. |
Reasons for making this change
This is a rebase and fix of #1228, which is stale. See also #675, #682
I've kept the change exactly the same (trusting @numical's work there), beyond rebasing I merely added b9f462e which fixes the tests. I don't know if it makes sense to also edit the documentation beyond the changelog, or if this should be implicit behavior?
Checklist
npm run test:updateto update snapshots, if needed.