Spaces:
Sleeping
Sleeping
ichieh commited on
Commit ·
b0a15a4
1
Parent(s): 1f3ce0c
Improve form validation and success message display
Browse files- templates/index.html +52 -16
templates/index.html
CHANGED
|
@@ -108,20 +108,21 @@
|
|
| 108 |
<div class="registration-section">
|
| 109 |
<h4 class="mb-3">登記資料</h4>
|
| 110 |
<div class="mb-3">
|
| 111 |
-
<label for="nickname" class="form-label">暱稱</label>
|
| 112 |
<input type="text" class="form-control" id="nickname" required>
|
| 113 |
</div>
|
| 114 |
<div class="mb-3">
|
| 115 |
-
<label for="email" class="form-label">Email</label>
|
| 116 |
<input type="email" class="form-control" id="email" required>
|
| 117 |
</div>
|
| 118 |
<div class="mb-3">
|
| 119 |
-
<label for="fb_link" class="form-label">FB個人連結</label>
|
| 120 |
<input type="url" class="form-control" id="fb_link">
|
| 121 |
</div>
|
| 122 |
<div class="mb-3">
|
| 123 |
-
<label for="introduction" class="form-label">自我介紹</label>
|
| 124 |
-
<textarea class="form-control" id="introduction" rows="3"></textarea>
|
|
|
|
| 125 |
</div>
|
| 126 |
<button class="btn btn-primary w-100" id="confirmBtn" disabled onclick="submitRegistration()">
|
| 127 |
確認選位
|
|
@@ -221,19 +222,34 @@
|
|
| 221 |
loadTables();
|
| 222 |
});
|
| 223 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
async function submitRegistration() {
|
| 225 |
if (!selectedTableId) {
|
| 226 |
-
Swal.fire(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
return;
|
| 228 |
}
|
| 229 |
|
| 230 |
-
const nickname = document.getElementById('nickname').value;
|
| 231 |
-
const email = document.getElementById('email').value;
|
| 232 |
-
const fb_link = document.getElementById('fb_link').value;
|
| 233 |
-
const introduction = document.getElementById('introduction').value;
|
| 234 |
|
| 235 |
if (!nickname || !email) {
|
| 236 |
-
Swal.fire(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
return;
|
| 238 |
}
|
| 239 |
|
|
@@ -255,24 +271,44 @@
|
|
| 255 |
const result = await response.json();
|
| 256 |
|
| 257 |
if (result.success) {
|
| 258 |
-
await Swal.fire(
|
| 259 |
-
|
| 260 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 261 |
// 清除表單
|
| 262 |
document.getElementById('nickname').value = '';
|
| 263 |
document.getElementById('email').value = '';
|
| 264 |
document.getElementById('fb_link').value = '';
|
| 265 |
document.getElementById('introduction').value = '';
|
|
|
|
|
|
|
| 266 |
// 禁用確認按鈕
|
| 267 |
document.getElementById('confirmBtn').disabled = true;
|
|
|
|
| 268 |
// 清除選擇的桌號
|
| 269 |
selectedTableId = null;
|
|
|
|
|
|
|
|
|
|
| 270 |
} else {
|
| 271 |
-
Swal.fire(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
}
|
| 273 |
} catch (error) {
|
| 274 |
console.error('Error:', error);
|
| 275 |
-
Swal.fire(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 276 |
}
|
| 277 |
}
|
| 278 |
</script>
|
|
|
|
| 108 |
<div class="registration-section">
|
| 109 |
<h4 class="mb-3">登記資料</h4>
|
| 110 |
<div class="mb-3">
|
| 111 |
+
<label for="nickname" class="form-label">暱稱 <span class="text-danger">*</span></label>
|
| 112 |
<input type="text" class="form-control" id="nickname" required>
|
| 113 |
</div>
|
| 114 |
<div class="mb-3">
|
| 115 |
+
<label for="email" class="form-label">Email <span class="text-danger">*</span></label>
|
| 116 |
<input type="email" class="form-control" id="email" required>
|
| 117 |
</div>
|
| 118 |
<div class="mb-3">
|
| 119 |
+
<label for="fb_link" class="form-label">FB個人連結 <small class="text-muted">(選填)</small></label>
|
| 120 |
<input type="url" class="form-control" id="fb_link">
|
| 121 |
</div>
|
| 122 |
<div class="mb-3">
|
| 123 |
+
<label for="introduction" class="form-label">自我介紹 <small class="text-muted">(選填,300字元內)</small></label>
|
| 124 |
+
<textarea class="form-control" id="introduction" rows="3" maxlength="300"></textarea>
|
| 125 |
+
<div class="form-text text-end"><span id="charCount">0</span>/300</div>
|
| 126 |
</div>
|
| 127 |
<button class="btn btn-primary w-100" id="confirmBtn" disabled onclick="submitRegistration()">
|
| 128 |
確認選位
|
|
|
|
| 222 |
loadTables();
|
| 223 |
});
|
| 224 |
|
| 225 |
+
// 字數計數器
|
| 226 |
+
document.getElementById('introduction').addEventListener('input', function() {
|
| 227 |
+
const currentLength = this.value.length;
|
| 228 |
+
document.getElementById('charCount').textContent = currentLength;
|
| 229 |
+
});
|
| 230 |
+
|
| 231 |
async function submitRegistration() {
|
| 232 |
if (!selectedTableId) {
|
| 233 |
+
Swal.fire({
|
| 234 |
+
icon: 'error',
|
| 235 |
+
title: '請先選擇座位',
|
| 236 |
+
confirmButtonText: '確定'
|
| 237 |
+
});
|
| 238 |
return;
|
| 239 |
}
|
| 240 |
|
| 241 |
+
const nickname = document.getElementById('nickname').value.trim();
|
| 242 |
+
const email = document.getElementById('email').value.trim();
|
| 243 |
+
const fb_link = document.getElementById('fb_link').value.trim();
|
| 244 |
+
const introduction = document.getElementById('introduction').value.trim();
|
| 245 |
|
| 246 |
if (!nickname || !email) {
|
| 247 |
+
Swal.fire({
|
| 248 |
+
icon: 'error',
|
| 249 |
+
title: '請填寫必要欄位',
|
| 250 |
+
text: '暱稱和Email為必填欄位',
|
| 251 |
+
confirmButtonText: '確定'
|
| 252 |
+
});
|
| 253 |
return;
|
| 254 |
}
|
| 255 |
|
|
|
|
| 271 |
const result = await response.json();
|
| 272 |
|
| 273 |
if (result.success) {
|
| 274 |
+
await Swal.fire({
|
| 275 |
+
icon: 'success',
|
| 276 |
+
title: '報名成功!',
|
| 277 |
+
text: '您已成功報名座位',
|
| 278 |
+
confirmButtonText: '確定'
|
| 279 |
+
});
|
| 280 |
+
|
| 281 |
// 清除表單
|
| 282 |
document.getElementById('nickname').value = '';
|
| 283 |
document.getElementById('email').value = '';
|
| 284 |
document.getElementById('fb_link').value = '';
|
| 285 |
document.getElementById('introduction').value = '';
|
| 286 |
+
document.getElementById('charCount').textContent = '0';
|
| 287 |
+
|
| 288 |
// 禁用確認按鈕
|
| 289 |
document.getElementById('confirmBtn').disabled = true;
|
| 290 |
+
|
| 291 |
// 清除選擇的桌號
|
| 292 |
selectedTableId = null;
|
| 293 |
+
|
| 294 |
+
// 重新載入桌次資料
|
| 295 |
+
await loadTables();
|
| 296 |
} else {
|
| 297 |
+
Swal.fire({
|
| 298 |
+
icon: 'error',
|
| 299 |
+
title: '報名失敗',
|
| 300 |
+
text: result.message || '報名失敗,請稍後再試',
|
| 301 |
+
confirmButtonText: '確定'
|
| 302 |
+
});
|
| 303 |
}
|
| 304 |
} catch (error) {
|
| 305 |
console.error('Error:', error);
|
| 306 |
+
Swal.fire({
|
| 307 |
+
icon: 'error',
|
| 308 |
+
title: '報名失敗',
|
| 309 |
+
text: '系統發生錯誤,請稍後再試',
|
| 310 |
+
confirmButtonText: '確定'
|
| 311 |
+
});
|
| 312 |
}
|
| 313 |
}
|
| 314 |
</script>
|