chore: Add validation for start and end dates in collection forms
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user