From f6d4a726708e59044fb9f43fe696890dbd5fdda1 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Sun, 6 Sep 2020 17:52:30 +0300 Subject: [PATCH] Collection edit: validate colors before allowing saving. --- src/Collections/CollectionEdit.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Collections/CollectionEdit.tsx b/src/Collections/CollectionEdit.tsx index d22ea9b..b11d7da 100644 --- a/src/Collections/CollectionEdit.tsx +++ b/src/Collections/CollectionEdit.tsx @@ -81,12 +81,12 @@ export default function CollectionEdit(props: PropsType) { saveErrors.name = fieldRequired; } - if (selectedColor && !color) { + if (color && !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(color)) { saveErrors.color = "Must be of the form #RRGGBB or #RRGGBBAA or empty"; } + setErrors(saveErrors); if (Object.keys(saveErrors).length > 0) { - setErrors(saveErrors); return; }