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

* now bookingFields identifier supports - and _ characters but no special characters

* fix: unit test

---------

Co-authored-by: Amit Sharma <74371312+Amit91848@users.noreply.github.com>
Co-authored-by: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com>
This commit is contained in:
Arnav Nath
2024-08-26 12:15:02 +02:00
committed by GitHub
co-authored by Amit Sharma Anik Dhabal Babu
parent 758423ecf9
commit 6529b49c3c
2 changed files with 10 additions and 6 deletions
+9 -5
View File
@@ -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", () => {
+1 -1
View File
@@ -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, "-");
};