-
Notifications
You must be signed in to change notification settings - Fork 0
/
multi-step.js
46 lines (40 loc) · 1.43 KB
/
multi-step.js
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
document.addEventListener('DOMContentLoaded', function () {
var currentStep = 0;
var steps = document.querySelectorAll('.form-step');
var nextButtons = document.querySelectorAll('.next-step');
var prevButtons = document.querySelectorAll('.previous-step');
var form = document.getElementById('multiStepForm');
function showStep(step) {
steps.forEach(function (stepElement, index) {
stepElement.style.display = (index === step) ? 'block' : 'none';
});
}
function validateStep(step) {
var inputs = steps[step].querySelectorAll('input, textarea');
for (var i = 0; i < inputs.length; i++) {
if (!inputs[i].checkValidity()) {
inputs[i].reportValidity();
return false;
}
}
return true;
}
nextButtons.forEach(function (button) {
button.addEventListener('click', function () {
if (validateStep(currentStep)) {
currentStep++;
showStep(currentStep);
}
});
});
prevButtons.forEach(function (button) {
button.addEventListener('click', function () {
currentStep--;
showStep(currentStep);
});
});
// Initial anzeigen
showStep(currentStep);
// Google Places Autocomplete für Adressfeld
var autocomplete = new google.maps.places.Autocomplete(document.getElementById('address'));
});