Skip to content

Commit c3b2842

Browse files
committed
fix: corrected JS errors to make a update and installation possible again (#3455)
1 parent acf9ed0 commit c3b2842

File tree

2 files changed

+22
-34
lines changed

2 files changed

+22
-34
lines changed

phpmyfaq/assets/src/setup.ts

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@ document.addEventListener('DOMContentLoaded', () => {
2323
handlePasswordToggle();
2424

2525
// Switch between database selection
26-
const setupType = document.getElementById('sql_type');
26+
const setupType: HTMLElement | null = document.getElementById('sql_type');
2727
if (setupType) {
2828
setupType.addEventListener('change', selectDatabaseSetup);
2929
}
3030

3131
// Add more Elasticsearch server inputs
32-
const addElasticsearch = document.getElementById('pmf-add-elasticsearch-host');
32+
const addElasticsearch: HTMLElement | null = document.getElementById('pmf-add-elasticsearch-host');
3333
if (addElasticsearch) {
3434
addElasticsearch.addEventListener('click', addElasticsearchServerInput);
3535
}
3636

3737
// Wizard
38-
let currentTab = 0;
39-
const nextButton = document.getElementById('nextBtn');
40-
const prevButton = document.getElementById('prevBtn');
38+
let currentTab: number = 0;
39+
const nextButton: HTMLElement | null = document.getElementById('nextBtn');
40+
const prevButton: HTMLElement | null = document.getElementById('prevBtn');
4141
if (nextButton) {
4242
nextButton.addEventListener('click', (event) => {
4343
event.preventDefault();
@@ -52,15 +52,15 @@ document.addEventListener('DOMContentLoaded', () => {
5252
}
5353
showTab(currentTab);
5454

55-
function showTab(number) {
56-
const currentStep = document.getElementsByClassName('step');
55+
function showTab(number: number): void {
56+
const currentStep: HTMLCollectionOf<Element> = document.getElementsByClassName('step');
5757

5858
if (currentStep.length > 0) {
59-
currentStep[number].style.display = 'block';
59+
(currentStep[number] as HTMLElement).style.display = 'block';
6060
}
6161

62-
const prevButton = document.getElementById('prevBtn');
63-
const nextButton = document.getElementById('nextBtn');
62+
const prevButton: HTMLElement | null = document.getElementById('prevBtn');
63+
const nextButton: HTMLElement | null = document.getElementById('nextBtn');
6464

6565
if (prevButton && nextButton) {
6666
if (number === 0) {
@@ -77,39 +77,39 @@ document.addEventListener('DOMContentLoaded', () => {
7777
}
7878
}
7979

80-
const nextPrev = (n) => {
81-
const currentStep = document.getElementsByClassName('step');
82-
const prevButton = document.getElementById('prevBtn');
83-
const nextButton = document.getElementById('nextBtn');
84-
const installButton = document.getElementById('installingBtn');
80+
const nextPrev = (n: number) => {
81+
const currentStep: HTMLCollectionOf<Element> = document.getElementsByClassName('step');
82+
const prevButton = document.getElementById('prevBtn') as HTMLElement;
83+
const nextButton = document.getElementById('nextBtn') as HTMLElement;
84+
const installButton = document.getElementById('installingBtn') as HTMLElement;
8585

8686
if (n === 1 && !validateForm()) {
8787
return false;
8888
}
8989

90-
currentStep[currentTab].style.display = 'none';
90+
(currentStep[currentTab] as HTMLElement).style.display = 'none';
9191
currentTab = currentTab + n;
9292
if (currentTab >= currentStep.length) {
9393
prevButton.classList.add('d-none');
9494
nextButton.classList.add('d-none');
9595
installButton.classList.remove('d-none');
96-
document.getElementById('phpmyfaq-setup-form').submit();
96+
(document.getElementById('phpmyfaq-setup-form') as HTMLFormElement).submit();
9797
return false;
9898
}
9999

100100
showTab(currentTab);
101101
};
102102

103-
const validateForm = () => {
103+
const validateForm = (): boolean => {
104104
let currentStep,
105105
y,
106106
i,
107107
valid = true;
108-
currentStep = document.getElementsByClassName('step');
108+
currentStep = document.getElementsByClassName('step') as HTMLCollectionOf<HTMLElement>;
109109
y = currentStep[currentTab].querySelectorAll('input,select');
110110

111111
for (i = 0; i < y.length; i++) {
112-
if (y[i].value === '' && y[i].hasAttribute('required')) {
112+
if ((y[i] as HTMLInputElement).value === '' && y[i].hasAttribute('required')) {
113113
y[i].className += ' is-invalid';
114114
// and set the current valid status to false
115115
valid = false;
@@ -122,16 +122,4 @@ document.addEventListener('DOMContentLoaded', () => {
122122

123123
return valid; // return the valid status
124124
};
125-
126-
const resetValidateForm = () => {
127-
let currentStep, y, i;
128-
currentStep = document.getElementsByClassName('step');
129-
y = currentStep[currentTab].getElementsByTagName('input');
130-
131-
for (i = 0; i < y.length; i++) {
132-
if (y[i].value === '' && y[i].hasAttribute('required')) {
133-
y[i].className -= ' is-invalid';
134-
}
135-
}
136-
};
137125
});

phpmyfaq/assets/templates/setup/base.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<meta name="application-name" content="phpMyFAQ {{ newVersion }}">
88
<meta name="copyright" content="(c) 2001-{{ currentYear }} phpMyFAQ Team">
99
<link rel="stylesheet" href="../assets/public/styles.css">
10-
<script src="../assets/public/setup.js"></script>
10+
<script type="module" src="../assets/public/setup.js"></script>
1111
<link rel="shortcut icon" href="../assets/images/favicon.ico">
1212
</head>
1313
<body>
@@ -44,6 +44,6 @@
4444
</p>
4545
</footer>
4646

47-
<script src="../assets/public/update.js"></script>
47+
<script type="module" src="../assets/public/update.js"></script>
4848
</body>
4949
</html>

0 commit comments

Comments
 (0)