From d297d38b9c99888690a06175364eb637dfe32b8d Mon Sep 17 00:00:00 2001 From: Jan-Gerke Salomon Date: Thu, 9 Nov 2023 11:04:40 +0100 Subject: [PATCH] feat(de schema): use schema for max length for all text inputs --- .../form/createDataElementSchema.ts | 52 +++++++++++++++---- 1 file changed, 42 insertions(+), 10 deletions(-) diff --git a/src/pages/dataElements/form/createDataElementSchema.ts b/src/pages/dataElements/form/createDataElementSchema.ts index c7cc09c9..7ff523d4 100644 --- a/src/pages/dataElements/form/createDataElementSchema.ts +++ b/src/pages/dataElements/form/createDataElementSchema.ts @@ -12,33 +12,65 @@ export const createDataElementSchema = (schemas: ModelSchemas) => name: z .string() .min(1, { message: requiredMessage }) - .max(schemas.dataElement.properties.name.length || 255, { + .max(schemas.dataElement.properties.name.length as number, { message: max50Message, - }), + }) + .trim(), shortName: z .string() .min(1, { message: requiredMessage }) - .max(schemas.dataElement.properties.shortName.length || 255, { + .max(schemas.dataElement.properties.shortName.length as number, { + message: max50Message, + }) + .trim(), + code: z + .string() + .max(schemas.dataElement.properties.code.length as number, { message: max50Message, - }), - code: z.string().optional(), + }) + .trim() + .optional(), description: z .string() - .max(255, { + .max(schemas.dataElement.properties.description.length as number, { + message: i18n.t( + 'The value is to long. You can use up to 255 characters' + ), + }) + .trim() + .optional(), + formName: z + .string() + .max(schemas.dataElement.properties.formName.length as number, { + message: i18n.t( + 'The value is to long. You can use up to 255 characters' + ), + }) + .trim() + .optional(), + url: z + .string() + .max(schemas.dataElement.properties.url.length as number, { + message: i18n.t( + 'The value is to long. You can use up to 255 characters' + ), + }) + .trim() + .optional(), + fieldMask: z + .string() + .max(schemas.dataElement.properties.fieldMask.length as number, { message: i18n.t( 'The value is to long. You can use up to 255 characters' ), }) + .trim() .optional(), - url: z.string().optional(), style: z.object({ color: z.string().optional(), icon: z.string().optional(), }), - icon: z.string().optional(), - fieldMask: z.string().optional(), domainType: z.union([z.literal('AGGREGATE'), z.literal('TRACKER')]), - formName: z.string().optional(), valueType: z .union([ z.literal('TEXT'),