Add error if hideInAnswer:true and addExtraTags are used in the same mapping, fix #906

This commit is contained in:
pietervdvn 2022-06-28 01:38:57 +02:00
parent b9be22a932
commit e67c3ffa52
3 changed files with 7 additions and 20 deletions

View file

@ -206,6 +206,11 @@ export default class TagRenderingConfig {
} else if (mapping.hideInAnswer !== undefined) { } else if (mapping.hideInAnswer !== undefined) {
hideInAnswer = TagUtils.Tag(mapping.hideInAnswer, `${context}.mapping[${i}].hideInAnswer`); hideInAnswer = TagUtils.Tag(mapping.hideInAnswer, `${context}.mapping[${i}].hideInAnswer`);
} }
const addExtraTags = (mapping.addExtraTags ?? []).map((str, j) => TagUtils.SimpleTag(str, `${ctx}.addExtraTags[${j}]`));
if(hideInAnswer === true && addExtraTags.length > 0){
throw `${ctx}: Invalid mapping: 'hideInAnswer' is set to 'true', but 'addExtraTags' is enabled as well. This means that extra tags will be applied if this mapping is chosen as answer, but it cannot be chosen as answer. This either indicates a thought error or obsolete code that must be removed.`
}
let icon = undefined; let icon = undefined;
let iconClass = "small" let iconClass = "small"
if(mapping.icon !== undefined){ if(mapping.icon !== undefined){
@ -223,7 +228,7 @@ export default class TagRenderingConfig {
hideInAnswer, hideInAnswer,
icon, icon,
iconClass, iconClass,
addExtraTags: (mapping.addExtraTags ?? []).map((str, j) => TagUtils.SimpleTag(str, `${ctx}.addExtraTags[${j}]`)) addExtraTags
}; };
if (this.question) { if (this.question) {
if (hideInAnswer !== true && mp.if !== undefined && !mp.if.isUsableAsAnswer()) { if (hideInAnswer !== true && mp.if !== undefined && !mp.if.isUsableAsAnswer()) {

View file

@ -347,10 +347,7 @@
"fr": "Réservée aux élèves de lécole", "fr": "Réservée aux élèves de lécole",
"es": "Solo accesibles para estudiantes de la escuela" "es": "Solo accesibles para estudiantes de la escuela"
}, },
"hideInAnswer": true, "hideInAnswer": true
"addExtraTags": [
"fee=no"
]
}, },
{ {
"if": "access=private", "if": "access=private",

View file

@ -271,9 +271,6 @@
{ {
"if": "not:addr:unit=yes", "if": "not:addr:unit=yes",
"then": "<div class='subtle'>Sub-unit (e.g. 1, Flat 2, Unit C)</div><div>There is no sub-unit within this address</div>", "then": "<div class='subtle'>Sub-unit (e.g. 1, Flat 2, Unit C)</div><div>There is no sub-unit within this address</div>",
"addExtraTags": [
"addr:unit="
],
"hideInAnswer": true "hideInAnswer": true
}, },
{ {
@ -360,9 +357,6 @@
"then": { "then": {
"en": "<div class='subtle'>Number (e.g. 1, 1A, 2)</div><div>This building has no house number</div>" "en": "<div class='subtle'>Number (e.g. 1, 1A, 2)</div><div>This building has no house number</div>"
}, },
"addExtraTags": [
"addr:housenumber="
],
"hideInAnswer": true "hideInAnswer": true
}, },
{ {
@ -402,9 +396,6 @@
"then": { "then": {
"en": "<div class='subtle'>Place (e.g. Castle Mews, West Business Park)</div><div>No extra place name is given or needed</div>" "en": "<div class='subtle'>Place (e.g. Castle Mews, West Business Park)</div><div>No extra place name is given or needed</div>"
}, },
"addExtraTags": [
"addr:substreet="
],
"hideInAnswer": true "hideInAnswer": true
}, },
{ {
@ -448,9 +439,6 @@
"then": { "then": {
"en": "<div class='subtle'>Place (e.g. Castle Mews, West Business Park)</div><div>No extra place name is given or needed</div>" "en": "<div class='subtle'>Place (e.g. Castle Mews, West Business Park)</div><div>No extra place name is given or needed</div>"
}, },
"addExtraTags": [
"addr:substreet="
],
"hideInAnswer": true "hideInAnswer": true
}, },
{ {
@ -554,9 +542,6 @@
{ {
"if": "not:addr:parentstreet=yes", "if": "not:addr:parentstreet=yes",
"then": "<div class='subtle'>Parent street name</div><div>No parent street name is needed within this address</div>", "then": "<div class='subtle'>Parent street name</div><div>No parent street name is needed within this address</div>",
"addExtraTags": [
"addr:parentstreet="
],
"hideInAnswer": true "hideInAnswer": true
}, },
{ {