From 28576cdb7e8e07071ac587c25977173388c0af13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82?= <47248711+milewskibogumil@users.noreply.github.com> Date: Mon, 11 Nov 2024 15:15:17 +0100 Subject: [PATCH] add custom validation for city in Project_Collection --- .../schema/collectionTypes/Project_Collection.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/apps/sanity/schema/collectionTypes/Project_Collection.tsx b/apps/sanity/schema/collectionTypes/Project_Collection.tsx index 023d2fc..768ed4c 100644 --- a/apps/sanity/schema/collectionTypes/Project_Collection.tsx +++ b/apps/sanity/schema/collectionTypes/Project_Collection.tsx @@ -71,7 +71,16 @@ export default defineType({ direction: "horizontal", layout: 'radio', }, - validation: Rule => Rule.required(), + validation: Rule => [ + Rule.required(), + Rule.custom((value, context) => { + const name = (context.parent as { name: string })?.name; + if (name && value && name.includes(value)) { + return true; + } + return 'Zweryfikuj poprawność miasta' + }).warning(), + ], }), defineField({ name: 'startDate',