* Get the option text (e.g., "Yes", "No") - the label for this specific option
(inputElement)
| 61 | * Get the option text (e.g., "Yes", "No") - the label for this specific option |
| 62 | */ |
| 63 | getOptionText(inputElement) { |
| 64 | // 1. Check if wrapped in a label |
| 65 | const label = inputElement.closest('label'); |
| 66 | if (label) { |
| 67 | const clone = label.cloneNode(true); |
| 68 | const inputInClone = clone.querySelector('input'); |
| 69 | if (inputInClone) inputInClone.remove(); |
| 70 | const text = clone.textContent?.replace(/\s+/g, ' ').trim(); |
| 71 | if (text) return text; |
| 72 | } |
| 73 | |
| 74 | // 2. Check for adjacent text node |
| 75 | const next = inputElement.nextSibling; |
| 76 | if (next && next.nodeType === Node.TEXT_NODE) { |
| 77 | const text = next.textContent?.trim(); |
| 78 | if (text) return text; |
| 79 | } |
| 80 | |
| 81 | // 3. Check next element sibling |
| 82 | const nextEl = inputElement.nextElementSibling; |
| 83 | if (nextEl) { |
| 84 | const text = nextEl.textContent?.trim(); |
| 85 | if (text && text.length < 50) return text; |
| 86 | } |
| 87 | |
| 88 | // 4. Check for label[for="id"] |
| 89 | if (inputElement.id) { |
| 90 | const forLabel = document.querySelector(`label[for="${CSS.escape(inputElement.id)}"]`); |
| 91 | if (forLabel) return forLabel.textContent?.trim(); |
| 92 | } |
| 93 | |
| 94 | // 5. Fallback to value |
| 95 | return inputElement.value; |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Generate parameter name from question text |