Add feedback to wikidata-input, fix #1650

This commit is contained in:
Pieter Vander Vennet 2024-02-25 18:17:52 +01:00
parent 4e1f439127
commit db92a600d5
2 changed files with 17 additions and 2 deletions

View file

@ -785,7 +785,9 @@
"feedback": "This is not a valid web address"
},
"wikidata": {
"description": "A Wikidata identifier"
"description": "A Wikidata identifier",
"empty": "Please, enter some wikidata-entries",
"startsWithQ": "A wikidata identifier starts with Q and is followed by a number"
}
}
}

View file

@ -2,6 +2,8 @@ import Combine from "../../Base/Combine"
import Wikidata from "../../../Logic/Web/Wikidata"
import WikidataSearchBox from "../../Wikipedia/WikidataSearchBox"
import { Validator } from "../Validator"
import { Translation } from "../../i18n/Translation"
import Translations from "../../i18n/Translations"
export default class WikidataValidator extends Validator {
constructor() {
@ -12,12 +14,23 @@ export default class WikidataValidator extends Validator {
if (str === undefined) {
return false
}
if (str.length <= 2) {
if (str.length == 1) {
return false
}
return !str.split(";").some((str) => Wikidata.ExtractKey(str) === undefined)
}
getFeedback(s: string, _?: () => string): Translation | undefined {
const t = Translations.t.validation.wikidata
if (s === "") {
return t.empty
}
if (!s.match(/(Q[0-9]+)(;Q[0-9]+)*/)) {
return t.startsWithQ
}
return undefined
}
public reformat(str) {
if (str === undefined) {
return undefined