fixes
This commit is contained in:
@@ -15,13 +15,21 @@ export function DiscriminatorField({ field, value, onChange, error }: Props) {
|
||||
const discProp = field.discriminatorProperty ?? "type";
|
||||
const currentType = value?.[discProp] ?? "";
|
||||
|
||||
function defaultFieldValue(field: FieldConfig): any {
|
||||
if (field.enumValues) return field.enumValues[0];
|
||||
if (field.isArray) return [];
|
||||
if (field.type === "object") return {};
|
||||
if (field.type === "number" || field.type === "integer") return 0;
|
||||
return null;
|
||||
}
|
||||
|
||||
const handleTypeChange = useCallback((e: any) => {
|
||||
const newType = e.target.value;
|
||||
const option = options.find((o) => o.value === newType);
|
||||
const newValue: Record<string, any> = { [discProp]: newType };
|
||||
if (option) {
|
||||
for (const f of option.fields) {
|
||||
newValue[f.name] = f.enumValues?.[0] ?? f.type === "number" ? 0 : f.type === "integer" ? 0 : "";
|
||||
newValue[f.name] = defaultFieldValue(f);
|
||||
}
|
||||
}
|
||||
onChange(newValue);
|
||||
|
||||
Reference in New Issue
Block a user