Skip to content

Commit

Permalink
feat: remove required attribute from fields if hidden due to condition
Browse files Browse the repository at this point in the history
  • Loading branch information
svenvandescheur authored and kevinchappell committed Aug 30, 2020
1 parent 70bea58 commit dfb6e62
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/js/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,29 @@ export default class FormeoRenderer {
const assignMap = {
equals: elem => {
const propMap = {
value: () => (elem[targetProperty] = value),
isNotVisible: () => elem.parentElement.setAttribute('hidden', true),
isVisible: () => elem.parentElement.removeAttribute('hidden'),
value: () => {
elem[targetProperty] = value
},
isNotVisible: () => {
elem.parentElement.setAttribute('hidden', true)
elem.required = false // Hidden input cannot be required.
},
isVisible: () => {
elem.parentElement.removeAttribute('hidden')
elem.required = elem._required
},
}
propMap[targetProperty] && propMap[targetProperty]()
},
}

if (isAddress(target)) {
const elem = this.getComponent(target)

// Store required value.
if (elem && elem._required === undefined) {
elem._required = elem.required
}
assignMap[assignment] && assignMap[assignment](elem)
}
}
Expand Down

0 comments on commit dfb6e62

Please sign in to comment.