From a94452652d27c49c6cdf2815835b6c5baf77212c Mon Sep 17 00:00:00 2001 From: davidmurray Date: Tue, 16 May 2023 15:07:12 -0400 Subject: [PATCH] Add a textTransform property to the InputString widget. * This lets one force input to be lowercase, uppercase, etc. * This is necessary in order to force postal code to be uppercase, as specified in od_mtl_2023 issue #400 (https://github.com/chairemobilite/od_mtl_2023/issues/400) * This only changes how the text is displayed on the web page. It does not change the text that is sent to the backend. * Modify an InputString unit test to consider the new `textTransform` property * Add an example usage of textTransform to the postal code widget in the demo survey --- .../demo_survey/src/survey/widgets/home.tsx | 1 + .../src/services/widgets/WidgetConfig.ts | 1 + .../src/components/inputs/InputString.tsx | 1 + .../inputs/__tests__/InputString.test.tsx | 3 ++- .../__snapshots__/InputString.test.tsx.snap | 20 +++++++++++++++++++ 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/example/demo_survey/src/survey/widgets/home.tsx b/example/demo_survey/src/survey/widgets/home.tsx index 97d2438b..e93d48c8 100644 --- a/example/demo_survey/src/survey/widgets/home.tsx +++ b/example/demo_survey/src/survey/widgets/home.tsx @@ -444,6 +444,7 @@ export const homePostalCode = { inputType: "string", path: "home.postalCode", datatype: "string", + textTransform: "uppercase", twoColumns: true, label: { fr: "Code postal", diff --git a/packages/evolution-common/src/services/widgets/WidgetConfig.ts b/packages/evolution-common/src/services/widgets/WidgetConfig.ts index bc816ae2..14125269 100644 --- a/packages/evolution-common/src/services/widgets/WidgetConfig.ts +++ b/packages/evolution-common/src/services/widgets/WidgetConfig.ts @@ -37,6 +37,7 @@ export type InputStringType = { diff --git a/packages/evolution-frontend/src/components/inputs/InputString.tsx b/packages/evolution-frontend/src/components/inputs/InputString.tsx index 59e72069..5d47ac22 100644 --- a/packages/evolution-frontend/src/components/inputs/InputString.tsx +++ b/packages/evolution-frontend/src/components/inputs/InputString.tsx @@ -47,6 +47,7 @@ export const InputString = { datatype: 'string' as const, maxLength: 20, defaultValue: 'test', + textTransform: 'lowercase' as const, containsHtml: true, label: { fr: `Texte en français`, @@ -194,4 +195,4 @@ test('Test update value through props', () => { updateKey: 1 }); expect(inputElement.getDOMNode().value).toBe(updateByServerVal); -}); \ No newline at end of file +}); diff --git a/packages/evolution-frontend/src/components/inputs/__tests__/__snapshots__/InputString.test.tsx.snap b/packages/evolution-frontend/src/components/inputs/__tests__/__snapshots__/InputString.test.tsx.snap index 9f830ed7..6c7e80bd 100644 --- a/packages/evolution-frontend/src/components/inputs/__tests__/__snapshots__/InputString.test.tsx.snap +++ b/packages/evolution-frontend/src/components/inputs/__tests__/__snapshots__/InputString.test.tsx.snap @@ -8,6 +8,11 @@ exports[`Should correctly render InputString with a value of 0 1`] = ` maxLength={255} name="test" onChange={[Function]} + style={ + Object { + "textTransform": "none", + } + } type="text" value={0} /> @@ -22,6 +27,11 @@ exports[`Should correctly render InputString with all parameters 1`] = ` name="test" onBlur={[Function]} onChange={[Function]} + style={ + Object { + "textTransform": "lowercase", + } + } type="text" value="test" /> @@ -35,6 +45,11 @@ exports[`Should correctly render InputString with base parameters 1`] = ` maxLength={255} name="test" onChange={[Function]} + style={ + Object { + "textTransform": "none", + } + } type="text" value="value" /> @@ -49,6 +64,11 @@ exports[`Should correctly render InputString with default value as function 1`] name="test" onBlur={[Function]} onChange={[Function]} + style={ + Object { + "textTransform": "none", + } + } type="text" value="fctDefault" />