Skip to content

Commit c784177

Browse files
committed
fix: Default values for react code string
1 parent 883caeb commit c784177

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

  • src/components/form-builder/helpers

‎src/components/form-builder/helpers/zod.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,12 @@ const createStringSchemaAsString = (
167167

168168
export const getZodDefaultValues = (
169169
components: FormComponentModel[]
170-
): Record<string, string> => {
171-
const defaultValues: Record<string, string> = {};
170+
): Record<string, string | number | undefined> => {
171+
const defaultValues: Record<string, string | number | undefined> = {};
172172

173173
components.forEach((component) => {
174174
const componentId = component.getField("attributes.id");
175-
const defaultValue = component.getField("value") || "";
175+
const defaultValue = component.getField("value") || undefined;
176176
defaultValues[componentId] = defaultValue;
177177
});
178178

@@ -183,7 +183,7 @@ export const getZodDefaultValues = (
183183
export const getZodDefaultValuesAsString = (components: FormComponentModel[]) => {
184184
const defaultValues = getZodDefaultValues(components);
185185
return Object.entries(defaultValues).map(([key, value]) => {
186-
return `"${key}": "${value}"`;
186+
return `"${key}": ${typeof value === "string" ? `"${value}"` : value}`;
187187
}).join(",\n");
188188
};
189189

0 commit comments

Comments
 (0)