From 93b59496957d9e848bfdc2f4d26c37c6e3c825b0 Mon Sep 17 00:00:00 2001 From: Daniel Townsend Date: Thu, 2 May 2024 12:25:03 +0100 Subject: [PATCH] use `convertFormValue` in custom forms (#389) --- admin_ui/src/components/FormAdd.vue | 13 ++++++------- admin_ui/src/utils.ts | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/admin_ui/src/components/FormAdd.vue b/admin_ui/src/components/FormAdd.vue index bceda6aa..c2db6a52 100644 --- a/admin_ui/src/components/FormAdd.vue +++ b/admin_ui/src/components/FormAdd.vue @@ -46,7 +46,7 @@ import { defineComponent, type PropType } from "vue" import NewForm from "./NewForm.vue" import type { APIResponseMessage, FormConfig, Schema } from "../interfaces" -import { parseErrorResponse } from "../utils" +import { convertFormValue, parseErrorResponse } from "@/utils" import FormErrors from "./FormErrors.vue" const BASE_URL = import.meta.env.VITE_APP_BASE_URI @@ -100,12 +100,11 @@ export default defineComponent({ const key = i[0] let value: any = i[1] - if (value == "null") { - value = null - } else if (this.schema.properties[key].type == "array") { - value = JSON.parse(value) - } - json[key] = value + json[key] = convertFormValue({ + key, + value, + schema: this.schema + }) } try { diff --git a/admin_ui/src/utils.ts b/admin_ui/src/utils.ts index a4165be3..16f93040 100644 --- a/admin_ui/src/utils.ts +++ b/admin_ui/src/utils.ts @@ -139,7 +139,7 @@ export function convertFormValue(params: { if (value == "null") { value = null - } else if (property.extra.nullable && value == "") { + } else if (property.extra?.nullable && value == "") { value = null } else if (getType(property) == "array") { value = JSON.parse(String(value))