1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-22 14:29:36 +02:00

chore: Add validation for start and end dates in collection forms

This commit is contained in:
Sean Morley 2024-08-19 16:49:27 -04:00
parent a7d84c0a60
commit 6fea57d773
2 changed files with 21 additions and 0 deletions

View file

@ -47,6 +47,22 @@
const form = event.target as HTMLFormElement; const form = event.target as HTMLFormElement;
const formData = new FormData(form); const formData = new FormData(form);
if (collectionToEdit.end_date && collectionToEdit.start_date) {
if (new Date(collectionToEdit.start_date) > new Date(collectionToEdit.end_date)) {
addToast('error', 'Start date must be before end date');
return;
}
}
if (collectionToEdit.end_date && !collectionToEdit.start_date) {
addToast('error', 'Please provide a start date');
return;
}
if (collectionToEdit.start_date && !collectionToEdit.end_date) {
addToast('error', 'Please provide an end date');
return;
}
const response = await fetch(form.action, { const response = await fetch(form.action, {
method: form.method, method: form.method,
body: formData body: formData

View file

@ -53,6 +53,11 @@
return; return;
} }
if (newCollection.start_date && !newCollection.end_date) {
addToast('error', 'Please provide an end date');
return;
}
const response = await fetch(form.action, { const response = await fetch(form.action, {
method: form.method, method: form.method,
body: formData body: formData