forked from MapComplete/MapComplete
UX: indicate that a search field is actually a regex, add feedback to the filterview
This commit is contained in:
parent
5da63bf83a
commit
ebe7ff85f8
5 changed files with 39 additions and 7 deletions
22
src/UI/InputElement/Validators/RegexValidator.ts
Normal file
22
src/UI/InputElement/Validators/RegexValidator.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import StringValidator from "./StringValidator"
|
||||
import { s } from "vitest/dist/env-afee91f0"
|
||||
import { Translation } from "../../i18n/Translation"
|
||||
import Translations from "../../i18n/Translations"
|
||||
|
||||
export default class RegexValidator extends StringValidator{
|
||||
constructor() {
|
||||
super("regex", "Validates a regex")
|
||||
}
|
||||
|
||||
getFeedback(s: string): Translation | undefined {
|
||||
try{
|
||||
new RegExp(s)
|
||||
}catch (e) {
|
||||
return Translations.T("Not a valid Regex: "+e)
|
||||
}
|
||||
}
|
||||
|
||||
isValid(s: string): boolean {
|
||||
return this.getFeedback(s) === undefined
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue