T
TanStack17mo ago
foreign-sapphire

How to handle a nullable object in the form.

I have an object that is nullable but if I try to access it using <form.Field name="item.nullable_object"></form.Field> and it's null, an error is thrown. Think as the structure like this:
type Item = {
nullable_item: { id: string } | null;
}
type Item = {
nullable_item: { id: string } | null;
}
2 Replies
stormy-gold
stormy-gold17mo ago
What would be a usecase for null in a form?
foreign-sapphire
foreign-sapphireOP16mo ago
Sorry for the delay. Been going through a lot in the past few days. The use case mostly is that we have big forms that are have some related data from other models attached to them. We have a few one to one relations ships that we show in a single form. Some of the are optional. Something like this:
type ItemDetails = {
id: string;
name: string;
manufacurer: { id: string; name: string; } | null;
}
type ItemDetails = {
id: string;
name: string;
manufacurer: { id: string; name: string; } | null;
}
So the manufacurer for the item is optional. This is really killing the usage for me... We have a lot of related models which we show in the forms, and they can be null. Can't represent that right now without excessive workarounds and manual handling of things.

Did you find this page helpful?