forked from MapComplete/MapComplete
Fix filter selection for one option
This commit is contained in:
parent
6cb5803efd
commit
dc959e15f4
2 changed files with 5 additions and 5 deletions
|
@ -18,7 +18,7 @@ export default class FilterConfig {
|
||||||
originalTagsSpec: string | AndOrTagConfigJson
|
originalTagsSpec: string | AndOrTagConfigJson
|
||||||
fields: { name: string, type: string }[]
|
fields: { name: string, type: string }[]
|
||||||
}[];
|
}[];
|
||||||
public readonly defaultSelection : number
|
public readonly defaultSelection? : number
|
||||||
|
|
||||||
constructor(json: FilterConfigJson, context: string) {
|
constructor(json: FilterConfigJson, context: string) {
|
||||||
if (json.options === undefined) {
|
if (json.options === undefined) {
|
||||||
|
@ -79,7 +79,7 @@ export default class FilterConfig {
|
||||||
return {question: question, osmTags: osmTags, fields, originalTagsSpec: option.osmTags};
|
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) {
|
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.`
|
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 = ""
|
let defaultValue = ""
|
||||||
if(this.options.length > 1){
|
if(this.options.length > 1){
|
||||||
defaultValue = ""+this.defaultSelection
|
defaultValue = ""+(this.defaultSelection ?? 0)
|
||||||
}else{
|
}else{
|
||||||
// Only a single option
|
// Only a single option
|
||||||
if(this.defaultSelection > 0){
|
if(this.defaultSelection === 0){
|
||||||
defaultValue = "true"
|
defaultValue = "true"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue