Skip to content

Scheduling infrastructure for absolutely everyone.

feat: bookingFields identifier supports - and _ characters (#16353)

Arnav Nath6529b49c3ca2
diff --git a/packages/lib/getValidRhfFieldName.test.ts b/packages/lib/getValidRhfFieldName.test.ts
index 7d3d6738097..a7855ead2d3 100644
--- a/packages/lib/getValidRhfFieldName.test.ts
+++ b/packages/lib/getValidRhfFieldName.test.ts
@@ -8,9 +8,8 @@ describe("getValidRhfFieldName", () => {
expect(getValidRhfFieldName("HELLO")).toEqual("HELLO");
});
- it("should convert spaces, _, and any other special character to -", () => {
+ it("should convert spaces and any other special character to -", () => {
expect(getValidRhfFieldName("hello there")).toEqual("hello-there");
- expect(getValidRhfFieldName("hello_there")).toEqual("hello-there");
expect(getValidRhfFieldName("hello$there")).toEqual("hello-there");
expect(getValidRhfFieldName("$hello$there")).toEqual("-hello-there");
expect(getValidRhfFieldName("$hello.there")).toEqual("-hello-there");
@@ -20,9 +19,14 @@ describe("getValidRhfFieldName", () => {
// We don't really care about a hyphen in the end
it("should not remove dashes from start and end.", () => {
expect(getValidRhfFieldName("hello-there-")).toEqual("hello-there-");
- expect(getValidRhfFieldName("hello-there_")).toEqual("hello-there-");
- expect(getValidRhfFieldName("_hello-there_")).toEqual("-hello-there-");
- expect(getValidRhfFieldName("$hello-there_")).toEqual("-hello-there-");
+ expect(getValidRhfFieldName("-hello-there")).toEqual("-hello-there");
+ expect(getValidRhfFieldName("$hello-there-")).toEqual("-hello-there-");
+ });
+
+ it("should not remove underscore from start and end.", () => {
+ expect(getValidRhfFieldName("hello-there_")).toEqual("hello-there_");
+ expect(getValidRhfFieldName("_hello-there_")).toEqual("_hello-there_");
+ expect(getValidRhfFieldName("$hello-there_")).toEqual("-hello-there_");
});
it("should remove unicode and emoji characters", () => {
diff --git a/packages/lib/getValidRhfFieldName.ts b/packages/lib/getValidRhfFieldName.ts
index a0523813901..bb2a38fe2cf 100644
--- a/packages/lib/getValidRhfFieldName.ts
+++ b/packages/lib/getValidRhfFieldName.ts
@@ -1,5 +1,5 @@
export const getValidRhfFieldName = (fieldName: string) => {
// Remember that any transformation that you do here would run on System Field names as well. So, be careful and avoiding doing anything here that would modify the SystemField names.
// e.g. SystemField name currently have uppercases in them. So, no need to lowercase unless absolutely needed.
- return fieldName.replace(/[^a-zA-Z0-9]/g, "-");
+ return fieldName.replace(/[^a-zA-Z0-9-_]/g, "-");
};