Skip to content

Commit

Permalink
Merge pull request #1698 from PriyaGhosal/revert-1621-calender
Browse files Browse the repository at this point in the history
Revert "🛠️Fix : Calendar Date Validation: Allows Selection of Past Dates"
  • Loading branch information
PriyaGhosal authored Oct 28, 2024
2 parents 65bba55 + 904a5c9 commit 1b7ccb8
Showing 1 changed file with 0 additions and 33 deletions.
33 changes: 0 additions & 33 deletions book.html
Original file line number Diff line number Diff line change
Expand Up @@ -378,39 +378,6 @@ <h2>Book Your Trip</h2>
<input type="date" id="dates" name="dates" required />
<div class="error" id="datesError"></div>
</div>

<script>
// Function to set the minimum date to today
function setMinDate() {
const today = new Date();
const dd = String(today.getDate()).padStart(2, '0');
const mm = String(today.getMonth() + 1).padStart(2, '0'); // January is 0!
const yyyy = today.getFullYear();

// Format the date as YYYY-MM-DD
const minDate = yyyy + '-' + mm + '-' + dd;
document.getElementById("dates").setAttribute("min", minDate);
}

// Call the function when the document is loaded
document.addEventListener("DOMContentLoaded", setMinDate);

// Optional: Validate the date on form submission
document.querySelector("form").addEventListener("submit", function(event) {
const selectedDate = new Date(document.getElementById("dates").value);
const today = new Date();
today.setHours(0, 0, 0, 0); // Set time to midnight for comparison

if (selectedDate < today) {
event.preventDefault(); // Prevent form submission
document.getElementById("datesError").innerText = "Please select a date that is today or in the future.";
} else {
document.getElementById("datesError").innerText = ""; // Clear any previous error message
}
});
</script>


<div class="form-group">
<label for="transport">Mode of Transport:</label>
<select id="transport" name="transport" required>
Expand Down

0 comments on commit 1b7ccb8

Please sign in to comment.