Optional Map, required properties #206
Replies: 2 comments
-
I just noticed the |
Beta Was this translation helpful? Give feedback.
-
Hi @mauriceackel |
Beta Was this translation helpful? Give feedback.
-
I just noticed the |
Beta Was this translation helpful? Give feedback.
-
Hi @mauriceackel |
Beta Was this translation helpful? Give feedback.
-
Hi @fgatti675,
I've got a question regarding validation... Is it possible to have a schema like this:
That is: The parent map (
button
) is optional but one of it's child properties (text
) is required. This might seem strange at first. However, I think this is a quite common use case. A property might not exist on an object but when it does, it has to be of a certain type. The TypeScript equivalent would be something like:On a technical side I have already started to look into this. It seems there are two things that currently prevent this behavior:
This line makes it, that a map is always initialized as
key: {}
, even if none of its properties has a value. In comparison other keys that don't have a value are not included in the initialization. This could easily be solved though and I already have a patch in mind. I also think this should definitely be solved in some way. However, it might require some additional UI elements to remove the property if it already exists on the element?!Because there is no
.default(null).nullable()
, the default yup behavior is to check for this property.SOME ISSUES
If this was to be implemented, I see a view issues:
button
) will have been initialized, meaning that it is now required to enter the child properties. With the current UI, I guess there would be no way around this. There would need to be a button (e.g. a small "-") for map types and basically also array types that allow to set the value back tonull
if they should be excluded..default(null).nullable()
here. To prevent this behavior, one could check if the property is required ands only if not, add the.nullable()
.required: true
validation property could be removed from them.Have you ever considered the topic explained above? What are your thoughts on it? Am I thinking too complicated and there is an easier solution? Should I create a PR with my prototype?
Cheers
Maurice
Beta Was this translation helpful? Give feedback.
All reactions