| | |
| | | } |
| | | |
| | | window.prefixInput = function(input, prefix, replace = false) { |
| | | if (!input) { |
| | | console.warn('prefixInput called with null/undefined input'); |
| | | return; |
| | | } |
| | | let newId = replace ? prefix : `${prefix}${input.name}`; |
| | | if (input.labels.length > 0) { |
| | | if (input.labels && input.labels.length > 0) { |
| | | input.labels?.forEach(label => { |
| | | label.htmlFor = newId; |
| | | }); |
| | | } else { |
| | | if (input.nextElementSibling?.tagName === 'LABEL') { |
| | | input.nextElementSibling.htmlFor = newId; |
| | | }else if (input.previousElementSibling?.tagName === 'LABEL') { |
| | | input.previousElementSibling.htmlFor = newId; |
| | | } else { |
| | | let label = input.parentElement.querySelector(`label[for="${input.id}"]`); |
| | | if (label) { |
| | | label.htmlFor = newId; |
| | | } |
| | | } else if (input.previousElementSibling?.tagName === 'label') { |
| | | let label = input.previousElementSibling; |
| | | if (label) label.htmlFor = newId; |
| | | } else if (input.nextElementSibling?.tagName === 'label') { |
| | | let label = input.nextElementSibling; |
| | | if (label) label.htmlFor = newId; |
| | | }else { |
| | | let label = input.closest('[data-field]')?.querySelector(`label[for="${input.id}"]`); |
| | | if (label) { |
| | | label.htmlFor = newId; |
| | | } |
| | | } |
| | | |