Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(form): set null to multiple choice #1123

Merged
merged 1 commit into from
May 29, 2024
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
26 changes: 15 additions & 11 deletions server/initializers/forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,19 +379,23 @@ function generateApiUpdate (fields) {
} else {
// convert [{label: {bg, en, ...}}] into {bg: [...], en: [...], ...}
const mergedValues = {}
val.forEach((v) => {
// iterate over our defined languages as this is user provided structure and may contain unsafe keys
for (const lang of languages) {
if (lang in v.label) {
if (mergedValues[lang] == null) {
mergedValues[lang] = []
if (val.length === 0) {
localField(name).update(this, null, language)
} else {
val.forEach((v) => {
// iterate over our defined languages as this is user provided structure and may contain unsafe keys
for (const lang of languages) {
if (lang in v.label) {
if (mergedValues[lang] == null) {
mergedValues[lang] = []
}
mergedValues[lang].push(v.label[lang])
}
mergedValues[lang].push(v.label[lang])
}
}
})
const joinedValues = mapObject(mergedValues, (values) => values.join(' | '))
localField(name).update(this, joinedValues, language)
})
const joinedValues = mapObject(mergedValues, (values) => values.join(' | '))
localField(name).update(this, joinedValues, language)
}
}
break
}
Expand Down
Loading