Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/helpers/wizardHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -1004,13 +1004,32 @@ export const updateNodesByConditions = (template, project, productTemplates) =>
export const removeValuesOfHiddenNodes = (template, project) => {
let updatedProject = project

const fieldMap = {}
// iterates over all nodes to find out nodes with same fieldName
forEachNode(template, (nodeObject, node) => { // eslint-disable-line no-unused-vars
if (nodeObject.fieldName ) {
if (!fieldMap[nodeObject.fieldName]) {
fieldMap[nodeObject.fieldName] = []
}
fieldMap[nodeObject.fieldName].push(nodeObject)
}
})

forEachNode(template, (nodeObject, node) => {
const level = getNodeLevel(node)
let hasVisbleNodeWithSameCond = false
if (nodeObject.fieldName) {
fieldMap[nodeObject.fieldName].forEach((no) => {
if (!_.get(no, '__wizard.hiddenByCondition')) {
hasVisbleNodeWithSameCond = true
}
})
}

switch(level) {
// if some question is hidden, we remove it's value from the project data
case LEVEL.QUESTION:
if (_.get(nodeObject, '__wizard.hiddenByCondition') && _.get(updatedProject, nodeObject.fieldName)) {
if (_.get(nodeObject, '__wizard.hiddenByCondition') && !hasVisbleNodeWithSameCond && _.get(updatedProject, nodeObject.fieldName)) {
updatedProject = update(updatedProject, unflatten({
[nodeObject.fieldName]: { $set: undefined }
}))
Expand Down