Issues with Empty Objects in Optional Fields and Nested Schema Validation #4378
Unanswered
fdelgadodeleon
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello everyone,
I’m experiencing two issues related to handling empty objects in optional fields. I’d appreciate any guidance on how to address these scenarios.
Problem 1: Optional Object with Required Fields Fails Validation When Empty
When I have a schema with an optional object containing required fields, if I enter text into one of these fields and then delete it, the form validation fails because the object remains as an empty object (
{}
) informData
, even though it’s supposed to be optional. Here’s an example schema:Expected output:
Received output:
{ "address": {} }
The empty
address
object prevents validation from passing, as it appears informData
even when all fields are cleared. I’m looking for a way to remove theaddress
object entirely if all its required fields are empty so that validation will pass.Playground link with the example schema above.
Problem 2: Unnecessary Empty Object in Nested Schema
In another schema, I have a nested structure where I define a
fields
array that can contain items of various types (in this case,"string"
or"list"
types). Here’s the schema:Here si the playground link with this second example.
When I add a field of type
"list"
, the output includesdependsOn
as an empty object by default:Received output:
Expected output:
I would like dependsOn to only appear in the output if it has properties set. Is there a way to prevent dependsOn from being included as an empty object?
Thank you in advance for any insights on these two issues!
Beta Was this translation helpful? Give feedback.
All reactions