From 020469bcbfb9f3520d7440f023c72803835f75b2 Mon Sep 17 00:00:00 2001 From: Nolan Ehrstrom Date: Mon, 30 Sep 2024 13:11:27 -0700 Subject: [PATCH] Add dot_notation validator --- src/components/mixins/validation.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/components/mixins/validation.js b/src/components/mixins/validation.js index 800982d..0056128 100644 --- a/src/components/mixins/validation.js +++ b/src/components/mixins/validation.js @@ -304,6 +304,28 @@ export default { }, "Must have a value between :between" ); + + // Update screen builder's tests/e2e/specs/Builder.spec.js when changing this + Validator.register( + "dot_notation", + (path) => { + // Split the string by dots + const keys = path.split('.'); + + // Regular expression for valid keys: start with a letter, followed by letters, numbers, or underscores + const validKey = /^[a-zA-Z][a-zA-Z0-9_]*$/; + + // Check each key for validity + for (let key of keys) { + if (!validKey.test(key)) { + return false; + } + } + + return true; + }, + "Invalid variable name", + ); } } };