Frontend Validierung ob mindestens ein Ort und eine Rechtsform gewählt wurde um leeres Ergebnis zu vermeiden.

This commit is contained in:
Schrom01 2026-04-23 11:14:49 +02:00
parent 262943a425
commit a914efc011
1 changed files with 14 additions and 3 deletions

View File

@ -77,7 +77,7 @@ include "zefixAPI.php";
<!-- Firmenname -->
<div class="mb-4">
<label for="firma" class="form-label">Firmenname</label>
<label for="firma" class="form-label">Firmenname (optional)</label>
<div class="form-text mb-2">* kann als Platzhalter verwendet werden</div>
<input type="text" id="firma" name="firma" class="form-control" placeholder="z.B. Silias*">
</div>
@ -183,6 +183,9 @@ include "zefixAPI.php";
<div class="d-grid">
<button type="submit" class="btn btn-primary btn-lg">Export starten</button>
</div>
<div id="selectionValidationMessage" class="text-danger mt-2" style="display:none;">
Wählen Sie mindestens einen Ort und eine Rechtsform
</div>
</form>
@ -193,7 +196,15 @@ include "zefixAPI.php";
const forms = document.querySelectorAll('.needs-validation')
Array.prototype.slice.call(forms).forEach(function (form) {
form.addEventListener('submit', function (event) {
if (!form.checkValidity()) {
const hasSelectedSitz = document.querySelector('input[name="sitze[]"]:checked') !== null
const hasSelectedRechtsform = document.querySelector('input[name="rechtsformen[]"]:checked') !== null
const selectionValidationMessage = document.getElementById('selectionValidationMessage')
if (selectionValidationMessage) {
selectionValidationMessage.style.display = hasSelectedSitz && hasSelectedRechtsform ? 'none' : 'block'
}
if (!form.checkValidity() || !hasSelectedSitz || !hasSelectedRechtsform) {
event.preventDefault()
event.stopPropagation()
}
@ -452,4 +463,4 @@ include "zefixAPI.php";
</footer>
</body>
</html>
</html>