function fieldValue(field) { if (field.tagName === 'SELECT') { var opt = field.options[field.selectedIndex]; if (!opt) return ''; // Se a opção placeholder "Mês" estiver selecionada, não imprime nada var text = (opt.textContent || opt.text || '').trim(); if (text === 'Mês' || opt.value === '') return ''; return text; } if (field.type === 'radio' || field.type === 'checkbox') { return field.checked; } return field.value || ''; } // Converte os controles em texto estável para impressão, mantendo exatamente os valores digitados. // Lê os valores dos campos ORIGINAIS (cloneNode pode perder selectedIndex em alguns browsers). var originalFields = card.querySelectorAll('input, select, textarea'); var printCard = card.cloneNode(true); var printFields = printCard.querySelectorAll('input, select, textarea'); printFields.forEach(function (field, index) { var original = originalFields[index]; var value = fieldValue(original); // Radios: só parênteses (X) ou ( ), sem quadrado ☒/☐ if (original.type === 'radio') { var label = field.closest('label'); var mark = value ? '(X)' : '( )'; if (label) { var text = ''; label.childNodes.forEach(function (n) { if (n.nodeType === 3) text += n.textContent; }); text = text.trim() .replace(/^\(\s*[xX✓]?\s*\)\s*/, '') .replace(/^[☐☒]\s*/, '') .trim(); while (label.firstChild) label.removeChild(label.firstChild); label.appendChild(document.createTextNode(mark + (text ? ' ' + text : ''))); } else { field.parentNode.replaceChild(document.createTextNode(mark), field); } return; } // Checkboxes: mantém ☒ / ☐ if (original.type === 'checkbox') { var spanCb = document.createElement('span'); spanCb.className = 'psc-print-value'; spanCb.style.display = 'inline'; spanCb.style.border = 'none'; spanCb.style.padding = '0'; spanCb.style.minHeight = 'auto'; spanCb.style.background = 'transparent'; spanCb.textContent = value ? '☒' : '☐'; field.parentNode.replaceChild(spanCb, field); return; } var span = document.createElement('span'); span.className = 'psc-print-value'; if (field.classList.contains('month')) span.classList.add('month'); if (field.classList.contains('year')) span.classList.add('year'); // Textareas usam a classe para altura na impressão if (field.tagName === 'TEXTAREA') span.classList.add('psc-textarea'); span.textContent = value; field.parentNode.replaceChild(span, field); });