From db92a600d569adc02a86c70125feed64e624bdc5 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Sun, 25 Feb 2024 18:17:52 +0100 Subject: [PATCH] Add feedback to wikidata-input, fix #1650 --- langs/en.json | 4 +++- .../InputElement/Validators/WikidataValidator.ts | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/langs/en.json b/langs/en.json index 7f192dfac..6979f1fe8 100644 --- a/langs/en.json +++ b/langs/en.json @@ -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" } } } diff --git a/src/UI/InputElement/Validators/WikidataValidator.ts b/src/UI/InputElement/Validators/WikidataValidator.ts index 48910a5ab..b2fc48c48 100644 --- a/src/UI/InputElement/Validators/WikidataValidator.ts +++ b/src/UI/InputElement/Validators/WikidataValidator.ts @@ -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