Skip to content

Commit

Permalink
fix: label for attribute for cloned checkboxes
Browse files Browse the repository at this point in the history
makeRecrusiveIds truly recursive
  • Loading branch information
kevinchappell committed Jun 1, 2019
1 parent 2e664c9 commit 1dacddc
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/js/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,23 @@ const processOptions = ({ container, ...opts }) => {

const baseId = id => id.replace(/^f-/, '')

const recursiveNewIds = elem => {
elem.setAttribute('id', `f-${uuid()}`)
const recursiveNewIds = (elem, level = 0) => {
if (!level) {
elem.setAttribute('id', `f-${uuid()}`)
}
const elems = elem.querySelectorAll('*')
const elemsLength = elems.length
for (let i = 0; i < elemsLength; i++) {
const element = elems[i]
if (element.id) {
element.setAttribute('id', `f-${uuid()}`)
const label = element.parentElement.querySelector(`[for=${element.id}]`)
const newElementId = `f-${uuid()}`
element.setAttribute('id', newElementId)
if (label) {
label.setAttribute('for', newElementId)
}
}
recursiveNewIds(element, level + 1)
}
}

Expand Down

0 comments on commit 1dacddc

Please sign in to comment.