File size: 1,661 Bytes
629e7a5
5bab31c
558f996
629e7a5
 
 
 
558f996
 
5bab31c
629e7a5
 
 
 
 
5bab31c
 
629e7a5
 
 
 
 
 
5bab31c
629e7a5
 
 
 
 
558f996
 
629e7a5
 
5bab31c
 
 
 
629e7a5
 
5bab31c
 
629e7a5
 
 
 
 
 
 
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
"use strict";

const common_fonts = [
	"Arial", "Times New Roman", "Courier New", "Verdana", "Georgia", "Palatino",
	"Bookman Old Style", "Tahoma", "Century Gothic", "Lucida Console", "Monaco",
	"Bradley Hand", "Calibri", "Cambria", "Candara", "Consolas", "Constantia",
	"Corbel", "Franklin Gothic Medium", "Gabriola"
];

document.addEventListener("DOMContentLoaded", () => {
	const startTimeInput = document.querySelector("#start_time");
	const endTimeInput = document.querySelector("#end_time");

	[startTimeInput, endTimeInput].forEach(input => {
		input.addEventListener("input", () => validateTimeFormat(input));
	});

	document.querySelectorAll(".show-form").forEach(option => {
		option.addEventListener("click", () => {
			document.querySelectorAll(".show-form").forEach(opt => opt.classList.remove("active-option"));
			option.classList.add("active-option");
		});
	});

	document.querySelectorAll("#font").forEach(fontSelect => {
		common_fonts.forEach(font => {
			const option = new Option(font, font);
			fontSelect.add(option);
		});
	});

	document.querySelectorAll(".show-form").forEach(button => {
		button.addEventListener("click", event => showForm(event.target.dataset.formId));
	});
});

function showForm(formId) {
	document.querySelectorAll("#forms-container form").forEach(form => {
		form.style.display = form.id === formId ? "block" : "none";
	});
}

function validateTimeFormat(input) {
	const regex = /^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$/;
	const isValid = regex.test(input.value);
	input.setCustomValidity(isValid ? "" : "Invalid time format. Please use HH:MM:SS");
	input.style.borderColor = isValid ? "#ccc" : "red";
}