Unternehmensprofil anlegen
Erstellen Sie Ihr professionelles Unternehmensprofil für den AUV Görlitz
Profilbeispiel ansehen// FilePond so konfigurieren, dass Dateien im normalen Form-Submit landen
FilePond.setOptions({
storeAsFile: true
});
// ✅ Custom-IDs eindeutig machen
function normalizeCustomFileIds(context = document) {
// Alle Felder mit exakt data-custom-id="file"
const fields = context.querySelectorAll('[data-custom-id="file"]');
if (fields.length <= 1) return;
fields.forEach((field, index) => {
// Nur ändern, wenn noch kein Index existiert
const currentId = field.dataset.customId;
if (!currentId.match(/-\d+$/)) {
field.dataset.customId = `${currentId}-${index}`;
}
});
}
// ✅ FilePond in Repeatern initialisieren, ohne Bricks/Bricksforge zu zerstören
function reinitFilepondInRepeater(context = document) {
// Erst Custom-IDs im aktuellen Kontext normalisieren
normalizeCustomFileIds(context);
const filepondRoots = context.querySelectorAll('.filepond--root');
filepondRoots.forEach(root => {
// Wenn bereits neu initialisiert → skip
if (root.dataset.reinitialized === "true") return;
// WICHTIG: bestehenden Input verwenden
const input = root.querySelector('input[type="file"]');
if (!input) return;
// Name pro Feld beibehalten, nur auf Array erweitern
if (!input.name.endsWith('[]')) {
input.name = input.name + '[]';
}
// Mehrere Dateien pro Feld erlauben
input.multiple = true;
// Alte FilePond-Instanz zerstören, falls vorhanden
if (input._pond) {
input._pond.destroy();
}
// Neue FilePond-Instanz auf diesem Input
const pond = FilePond.create(input);
input._pond = pond;
// Markieren, damit wir es nicht doppelt machen
root.dataset.reinitialized = "true";
});
}
// 🔁 Beim Laden
document.addEventListener('DOMContentLoaded', () => {
normalizeCustomFileIds();
reinitFilepondInRepeater();
});
// 🔁 Bei DOM-Änderungen (z.B. neue Repeater-Items)
const observer = new MutationObserver(mutations => {
let hasNewNodes = false;
mutations.forEach(mutation => {
if (mutation.addedNodes.length > 0) {
hasNewNodes = true;
mutation.addedNodes.forEach(node => {
if (node.nodeType === 1) {
// Für neu hinzugefügte Bereiche: IDs normalisieren + FilePond setzen
reinitFilepondInRepeater(node);
}
});
}
});
// Falls global nötig, einmal IDs normalisieren
if (hasNewNodes) {
normalizeCustomFileIds();
reinitFilepondInRepeater();
}
});
observer.observe(document.body, {
childList: true,
subtree: true
});
document.addEventListener('bricksforge/repeater/itemAdded', function(e) {
const newItem = e.detail.item; // das neu hinzugefügte Repeater Element
reinitFilepond(newItem);
});
function reinitFilepond(context) {
const filepondRoots = context.querySelectorAll('.filepond--root');
filepondRoots.forEach(root => {
// 1️⃣ Alte Instanz zerstören falls vorhanden
if (root._pond) {
root._pond.destroy();
}
// 2️⃣ Geklonten DOM zurücksetzen
const originalInput = root.querySelector('input[type="file"]');
if (!originalInput) return;
const cleanName = originalInput.name;
root.innerHTML = '';
const freshInput = document.createElement('input');
freshInput.type = 'file';
freshInput.name = cleanName;
freshInput.multiple = true;
root.appendChild(freshInput);
// 3️⃣ Neue Filepond Instanz erzeugen
const pond = FilePond.create(freshInput);
// Referenz speichern
root._pond = pond;
});
}