Merge pull request #252 from Hexastack/fix/form-block-trigger-regex-check-format

fix(frontend): regex input control
This commit is contained in:
Med Marrouchi 2024-10-21 15:04:22 +01:00 committed by GitHub
commit b2c32fe27d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -266,9 +266,20 @@ const PatternInput: FC<PatternInputProps> = ({
{typeof value === "string" && patternType === "regex" ? (
<RegexInput
{...registerInput(t("message.regex_is_invalid"), idx, {
validate: (value) =>
(value.trim() !== "" && value !== "/") ??
t("message.regex_is_invalid"),
validate: (pattern) => {
try {
if (
pattern.at(0) === "/" &&
pattern.at(-1) === "/" &&
typeof pattern === "string"
)
new RegExp(pattern.slice(1, -1));
return true;
} catch (_e) {
return t("message.regex_is_invalid");
}
},
setValueAs: (v) => `/${v}/`,
})}
label={t("label.regex")}