Skip to content

Commit

Permalink
fix(form): allow setting null value for multiple choice input when up…
Browse files Browse the repository at this point in the history
…dating form
  • Loading branch information
onyxvd committed May 26, 2024
1 parent 168dabc commit 523b4ea
Showing 1 changed file with 15 additions and 11 deletions.
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

0 comments on commit 523b4ea

Please sign in to comment.