-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatetime-picker.html
126 lines (122 loc) · 4.32 KB
/
datetime-picker.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Date & Time Picker</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">
<style>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: flex-start;
height: 100vh;
background-color: #f0f0f0;
margin: 0;
padding-top: 30px;
}
.container {
background-color: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
text-align: center;
max-width: 400px;
width: 100%;
position: relative;
}
.container h2 {
margin-bottom: 20px;
}
.input-group {
margin-bottom: 20px;
}
.input-group input {
padding: 10px;
border-radius: 5px;
border: 1px solid #ccc;
width: 100%;
box-sizing: border-box;
}
.submit-btn {
padding: 10px 20px;
border: none;
border-radius: 5px;
background-color: #007bff;
color: white;
font-size: 16px;
cursor: pointer;
transition: background-color 0.3s;
}
.submit-btn:hover {
background-color: #0056b3;
}
.error-popup {
background-color: #f8d7da;
color: #721c24;
padding: 10px;
border-radius: 5px;
border: 1px solid #f5c6cb;
display: none;
margin-top: 20px;
width: 100%;
position: absolute;
bottom: -60px;
}
</style>
</head>
<body>
<div class="container">
<h2>Pick Date & Time</h2>
<div class="input-group">
<label for="datetime">Date & Time:</label>
<input type="text" id="datetime" name="datetime">
</div>
<button class="submit-btn" onclick="submitDateTime()">Submit</button>
<div id="error-popup" class="error-popup"></div>
</div>
<script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>
<script src="https://telegram.org/js/telegram-web-app.js"></script>
<script>
const now = new Date();
const formattedDateTime = now.getFullYear() + "-" +
String(now.getMonth() + 1).padStart(2, '0') + "-" +
String(now.getDate()).padStart(2, '0') + " " +
String(now.getHours()).padStart(2, '0') + ":" +
String(now.getMinutes()).padStart(2, '0');
flatpickr("#datetime", {
enableTime: true,
dateFormat: "Y-m-d H:i",
minDate: formattedDateTime, // Block past dates and hours
time_24hr: true
});
function submitDateTime() {
const datetime = document.getElementById('datetime').value;
const errorPopup = document.getElementById('error-popup');
try {
if (datetime) {
// Pass the selected date and time back to the Telegram bot
if (window.Telegram.WebApp) {
window.Telegram.WebApp.sendData(datetime); // Send data back to the bot
setTimeout(() => {
window.Telegram.WebApp.close(); // Close the web app after sending data
}, 100); // Delay to ensure data is sent
} else {
throw new Error('Telegram WebApp API not found. Date and time cannot be sent.');
}
} else {
throw new Error('Please select both date and time.');
}
} catch (error) {
errorPopup.textContent = error.message;
errorPopup.style.display = 'block';
setTimeout(() => {
errorPopup.style.display = 'none';
}, 5000); // Hide the popup after 5 seconds
}
}
Telegram.WebApp.ready();
</script>
</body>
</html>