60 lines
2.3 KiB
JavaScript
60 lines
2.3 KiB
JavaScript
(function () {
|
|
// Licznik znaków opisu
|
|
const opis = document.getElementById('opis');
|
|
const opisCount = document.getElementById('opisCount');
|
|
if (opis && opisCount) {
|
|
const updateCount = () => opisCount.textContent = opis.value.length.toString();
|
|
opis.addEventListener('input', updateCount);
|
|
updateCount();
|
|
}
|
|
|
|
// IBAN: tylko cyfry, auto-grupowanie co 4
|
|
const iban = document.getElementById('numer_konta');
|
|
if (iban) {
|
|
iban.addEventListener('input', () => {
|
|
const digits = iban.value.replace(/\D/g, '').slice(0, 26); // 26 cyfr po "PL"
|
|
const chunked = digits.replace(/(.{4})/g, '$1 ').trim();
|
|
iban.value = chunked;
|
|
});
|
|
}
|
|
|
|
// BLIK telefon: tylko cyfry, format 3-3-3
|
|
const tel = document.getElementById('numer_telefonu_blik');
|
|
if (tel) {
|
|
tel.addEventListener('input', () => {
|
|
const digits = tel.value.replace(/\D/g, '').slice(0, 9);
|
|
const parts = [];
|
|
if (digits.length > 0) parts.push(digits.substring(0, 3));
|
|
if (digits.length > 3) parts.push(digits.substring(3, 6));
|
|
if (digits.length > 6) parts.push(digits.substring(6, 9));
|
|
tel.value = parts.join(' ');
|
|
});
|
|
}
|
|
|
|
// „Ustaw globalne” z data-atrybutów (bez wstrzykiwania wartości w JS)
|
|
const setGlobalBtn = document.getElementById('ustaw-globalne');
|
|
if (setGlobalBtn && iban && tel) {
|
|
setGlobalBtn.addEventListener('click', () => {
|
|
const gIban = setGlobalBtn.dataset.iban || '';
|
|
const gBlik = setGlobalBtn.dataset.blik || '';
|
|
if (gIban) {
|
|
iban.value = gIban.replace(/\D/g, '').replace(/(.{4})/g, '$1 ').trim();
|
|
}
|
|
if (gBlik) {
|
|
const d = gBlik.replace(/\D/g, '').slice(0, 9);
|
|
const p = [d.slice(0, 3), d.slice(3, 6), d.slice(6, 9)].filter(Boolean).join(' ');
|
|
tel.value = p;
|
|
}
|
|
iban.dispatchEvent(new Event('input'));
|
|
tel.dispatchEvent(new Event('input'));
|
|
});
|
|
}
|
|
|
|
// Cel: minimalna wartość
|
|
const cel = document.getElementById('cel');
|
|
if (cel) {
|
|
cel.addEventListener('change', () => {
|
|
if (cel.value && Number(cel.value) < 0.01) cel.value = '0.01';
|
|
});
|
|
}
|
|
})(); |