mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-08 22:53:25 +00:00
fix: trim values before form validation
This commit is contained in:
@@ -21,11 +21,13 @@ export default function EditCollectionPage({
|
||||
nextId: collection.nextId,
|
||||
});
|
||||
const canSubmit = useMemo<boolean>(() => {
|
||||
const trimmedName = data.name.trim();
|
||||
const trimmedDescription = data.description?.trim();
|
||||
const isFormEdited =
|
||||
data.name !== collection.name ||
|
||||
data.description !== collection.description ||
|
||||
trimmedName !== collection.name ||
|
||||
trimmedDescription !== collection.description ||
|
||||
data.visibility !== collection.visibility;
|
||||
const isFormValid = data.name !== '';
|
||||
const isFormValid = trimmedName !== '';
|
||||
return isFormEdited && isFormValid && !processing;
|
||||
}, [data, collection]);
|
||||
|
||||
|
||||
@@ -22,16 +22,20 @@ export default function EditLinkPage({
|
||||
collectionId: link.collectionId,
|
||||
});
|
||||
const canSubmit = useMemo<boolean>(() => {
|
||||
const trimmedName = data.name.trim();
|
||||
const trimmedDescription = data.description?.trim();
|
||||
const trimmedUrl = data.url.trim();
|
||||
|
||||
const isFormEdited =
|
||||
data.name !== link.name ||
|
||||
data.url !== link.url ||
|
||||
data.description !== link.description ||
|
||||
trimmedName !== link.name ||
|
||||
trimmedUrl !== link.url ||
|
||||
trimmedDescription !== link.description ||
|
||||
data.favorite !== link.favorite ||
|
||||
data.collectionId !== link.collectionId;
|
||||
|
||||
const isFormValid =
|
||||
data.name !== '' &&
|
||||
isValidHttpUrl(data.url) &&
|
||||
trimmedName !== '' &&
|
||||
isValidHttpUrl(trimmedUrl) &&
|
||||
data.favorite !== null &&
|
||||
data.collectionId !== null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user