Skip to content

Commit

Permalink
Merge pull request #255 from seanmorley15/development
Browse files Browse the repository at this point in the history
chore: Add validation for start and end dates in collection forms
  • Loading branch information
seanmorley15 authored Aug 19, 2024
2 parents 4e422d5 + 6fea57d commit 2beb581
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
16 changes: 16 additions & 0 deletions frontend/src/lib/components/EditCollection.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/lib/components/NewCollection.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2beb581

Please sign in to comment.