From 1073ac4253168e20f5a67c9922d9300ed54dc91f Mon Sep 17 00:00:00 2001
From: Kentai Radiquum
Date: Fri, 16 Aug 2024 14:14:29 +0500
Subject: [PATCH] add string serialization and max input length to create
collection form
---
app/pages/CreateCollection.tsx | 24 ++++++++++++++++++++----
1 file changed, 20 insertions(+), 4 deletions(-)
diff --git a/app/pages/CreateCollection.tsx b/app/pages/CreateCollection.tsx
index 38b3904..0f2cd40 100644
--- a/app/pages/CreateCollection.tsx
+++ b/app/pages/CreateCollection.tsx
@@ -27,6 +27,10 @@ export const CreateCollectionPage = () => {
title: "",
description: "",
});
+ const [stringLength, setStringLength] = useState({
+ title: 0,
+ description: 0,
+ });
const collection_id = searchParams.get("id") || null;
const mode = searchParams.get("mode") || null;
@@ -78,14 +82,22 @@ export const CreateCollectionPage = () => {
};
function handleInput(e) {
+ const regex = /[^a-zA-Zа-яА-Я0-9_.,:()!? \[\]]/g;
setCollectionInfo({
...collectionInfo,
- [e.target.name]: e.target.value,
+ [e.target.name]: e.target.value.replace(regex, ""),
+ });
+ setStringLength({
+ ...stringLength,
+ [e.target.name]: e.target.value.replace(regex, "").length,
});
}
function submit(e) {
e.preventDefault();
+
+ console.log(collectionInfo.title.length);
+
console.log({
...collectionInfo,
private: isPrivate,
@@ -100,7 +112,7 @@ export const CreateCollectionPage = () => {
{edit ? "Редактирование коллекции" : "Создание коллекции"}