Fix filter selection for one option

This commit is contained in:
pietervdvn 2022-02-14 15:59:42 +01:00
parent 6cb5803efd
commit dc959e15f4
2 changed files with 5 additions and 5 deletions

View file

@ -71,7 +71,7 @@ export class QueryParameters {
QueryParameters.knownSources[key] = source;
}
}
}
private static Serialize() {

View file

@ -18,7 +18,7 @@ export default class FilterConfig {
originalTagsSpec: string | AndOrTagConfigJson
fields: { name: string, type: string }[]
}[];
public readonly defaultSelection : number
public readonly defaultSelection? : number
constructor(json: FilterConfigJson, context: string) {
if (json.options === undefined) {
@ -79,7 +79,7 @@ export default class FilterConfig {
return {question: question, osmTags: osmTags, fields, originalTagsSpec: option.osmTags};
});
this.defaultSelection = defaultSelection ?? 0
this.defaultSelection = defaultSelection
if (this.options.some(o => o.fields.length > 0) && this.options.length > 1) {
throw `Invalid filter at ${context}: a filter with textfields should only offer a single option.`
@ -103,10 +103,10 @@ export default class FilterConfig {
let defaultValue = ""
if(this.options.length > 1){
defaultValue = ""+this.defaultSelection
defaultValue = ""+(this.defaultSelection ?? 0)
}else{
// Only a single option
if(this.defaultSelection > 0){
if(this.defaultSelection === 0){
defaultValue = "true"
}
}