1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-08-02 19:55:18 +02:00

Merge pull request #255 from seanmorley15/development

chore: Add validation for start and end dates in collection forms
This commit is contained in:
Sean Morley 2024-08-19 16:52:35 -04:00 committed by GitHub
commit 2beb5819c8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 0 deletions

View file

@ -47,6 +47,22 @@
const form = event.target as HTMLFormElement;
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, {
method: form.method,
body: formData

View file

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