-
-
Notifications
You must be signed in to change notification settings - Fork 660
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When selecting a start datetime, the end datetime should be after the start datetime. #6143. github - Harshit-7373.
- Loading branch information
1 parent
8ea1215
commit 1cdcdbe
Showing
3 changed files
with
124 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Event Scheduler</title> | ||
<script defer src="script.js"></script> | ||
</head> | ||
<body> | ||
<form id="event-form"> | ||
<label for="start-datetime">Start Datetime:</label> | ||
<input type="datetime-local" id="start-datetime" name="start-datetime" required> | ||
|
||
<label for="end-datetime">End Datetime:</label> | ||
<input type="datetime-local" id="end-datetime" name="end-datetime"> | ||
|
||
<label for="all-day-checkbox">All-Day Event:</label> | ||
<input type="checkbox" id="all-day-checkbox"> | ||
|
||
<label for="is-recurring">Recurring Event:</label> | ||
<input type="checkbox" id="is-recurring"> | ||
|
||
<button type="submit">Save Event</button> | ||
</form> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
document.getElementById("event-form").addEventListener("submit", function (event) { | ||
event.preventDefault(); | ||
|
||
const startField = document.getElementById("start-datetime"); | ||
const endField = document.getElementById("end-datetime"); | ||
const allDayCheckbox = document.getElementById("all-day-checkbox"); | ||
|
||
const start = new Date(startField.value); | ||
const end = new Date(endField.value); | ||
|
||
// Validate start and end times | ||
if (!allDayCheckbox.checked && end <= start) { | ||
alert("End datetime must be after start datetime."); | ||
return; | ||
} | ||
|
||
// Handle all-day event logic | ||
if (allDayCheckbox.checked) { | ||
const startDate = start.toISOString().slice(0, 10); | ||
startField.value = `${startDate}T00:00`; | ||
endField.value = `${startDate}T23:59`; | ||
} | ||
|
||
// Send data to the backend | ||
const eventData = { | ||
startDatetime: startField.value, | ||
endDatetime: endField.value, | ||
isAllDay: allDayCheckbox.checked, | ||
isRecurring: document.getElementById("is-recurring").checked, | ||
}; | ||
|
||
fetch("/create-event", { | ||
method: "POST", | ||
headers: { "Content-Type": "application/json" }, | ||
body: JSON.stringify(eventData), | ||
}) | ||
.then((response) => response.json()) | ||
.then((data) => { | ||
if (data.error) { | ||
alert(data.error); | ||
} else { | ||
alert("Event saved successfully!"); | ||
} | ||
}) | ||
.catch((error) => console.error("Error:", error)); | ||
}); |