From b0963bbca17e2b1b925aa775b5bbf104d206bacf Mon Sep 17 00:00:00 2001 From: Sai Charan Date: Thu, 4 Jul 2024 14:29:58 +0530 Subject: [PATCH 1/2] fix: add regex check on phone number change --- .../Widgets/PhoneInput/PhoneInput_Part2_spec.ts | 3 +++ .../widgets/PhoneInputWidget/widget/index.tsx | 16 +++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/client/cypress/e2e/Regression/ClientSide/Widgets/PhoneInput/PhoneInput_Part2_spec.ts b/app/client/cypress/e2e/Regression/ClientSide/Widgets/PhoneInput/PhoneInput_Part2_spec.ts index 9eede0aa2b78..cbf6b2ecf1cc 100644 --- a/app/client/cypress/e2e/Regression/ClientSide/Widgets/PhoneInput/PhoneInput_Part2_spec.ts +++ b/app/client/cypress/e2e/Regression/ClientSide/Widgets/PhoneInput/PhoneInput_Part2_spec.ts @@ -292,6 +292,9 @@ describe( agHelper.ClearNType(locators._input, "100"); agHelper.ValidateToastMessage("Value Changed"); + agHelper.WaitUntilToastDisappear("Value Changed"); + agHelper.ClearNType(locators._input, "a"); + cy.get(locators._toastMsg).should("not.exist"); // onFocus propPane.SelectPlatformFunction("onFocus", "Show alert"); diff --git a/app/client/src/widgets/PhoneInputWidget/widget/index.tsx b/app/client/src/widgets/PhoneInputWidget/widget/index.tsx index cfad9e61b9b7..69f6694d7ef8 100644 --- a/app/client/src/widgets/PhoneInputWidget/widget/index.tsx +++ b/app/client/src/widgets/PhoneInputWidget/widget/index.tsx @@ -408,13 +408,15 @@ class PhoneInputWidget extends BaseInputWidget< "value", parseIncompletePhoneNumber(formattedValue), ); - this.props.updateWidgetMetaProperty("text", formattedValue, { - triggerPropertyName: "onTextChanged", - dynamicString: this.props.onTextChanged, - event: { - type: EventType.ON_TEXT_CHANGE, - }, - }); + if (/^(?!\s)[\d\s()+-]*$/.test(value)) { + this.props.updateWidgetMetaProperty("text", formattedValue, { + triggerPropertyName: "onTextChanged", + dynamicString: this.props.onTextChanged, + event: { + type: EventType.ON_TEXT_CHANGE, + }, + }); + } if (!this.props.isDirty) { this.props.updateWidgetMetaProperty("isDirty", true); } From ed419467d6ac7b97f76ff3b1db4e1eaeb50583b5 Mon Sep 17 00:00:00 2001 From: Sai Charan Date: Wed, 17 Jul 2024 15:52:21 +0530 Subject: [PATCH 2/2] feat: add comment for regex in phone input widget --- app/client/src/widgets/PhoneInputWidget/widget/index.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/client/src/widgets/PhoneInputWidget/widget/index.tsx b/app/client/src/widgets/PhoneInputWidget/widget/index.tsx index 69f6694d7ef8..f6fd4be26bce 100644 --- a/app/client/src/widgets/PhoneInputWidget/widget/index.tsx +++ b/app/client/src/widgets/PhoneInputWidget/widget/index.tsx @@ -408,6 +408,9 @@ class PhoneInputWidget extends BaseInputWidget< "value", parseIncompletePhoneNumber(formattedValue), ); + // This regular expression validates that the input: + // - Does not start with a whitespace character + // - Contains only digits, spaces, parentheses, plus, and minus symbols if (/^(?!\s)[\d\s()+-]*$/.test(value)) { this.props.updateWidgetMetaProperty("text", formattedValue, { triggerPropertyName: "onTextChanged",